Repo rebuild

This commit is contained in:
Mark Gregory
2026-09-15 12:33:28 +01:00
commit be28c4feec
5629 changed files with 317074 additions and 0 deletions
@@ -0,0 +1,90 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('companies', function (Blueprint $table): void {
$table->id();
$table->uuid('uuid')->unique();
$table->string('name');
$table->string('slug')->unique();
$table->string('status')->default('active')->index();
$table->string('timezone')->default('Europe/London');
$table->boolean('is_system_company')->default(false)->index();
$table->string('stripe_customer_id')->nullable()->index();
$table->string('billing_email')->nullable();
$table->json('settings')->nullable();
$table->timestamps();
$table->softDeletes();
});
Schema::table('users', function (Blueprint $table): void {
$table->foreignId('company_id')->nullable()->after('id')->constrained('companies')->nullOnDelete();
$table->boolean('is_platform_admin')->default(false)->after('password');
$table->boolean('is_company_admin')->default(false)->after('is_platform_admin');
$table->string('status')->default('active')->after('is_company_admin')->index();
});
Schema::create('license_keys', function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->constrained('companies')->cascadeOnDelete();
$table->string('key_hash', 64)->unique();
$table->string('key_prefix', 16)->index();
$table->string('label');
$table->string('plan')->default('standard')->index();
$table->unsignedInteger('max_users')->default(10);
$table->boolean('is_active')->default(true)->index();
$table->timestamp('starts_at')->nullable();
$table->timestamp('expires_at')->nullable()->index();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('revoked_at')->nullable()->index();
$table->timestamps();
});
Schema::create('payments', function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->constrained('companies')->cascadeOnDelete();
$table->string('stripe_payment_intent_id')->nullable()->unique();
$table->string('stripe_invoice_id')->nullable()->index();
$table->unsignedInteger('amount')->default(0);
$table->string('currency', 3)->default('gbp');
$table->string('status')->default('pending')->index();
$table->string('description')->nullable();
$table->timestamp('paid_at')->nullable();
$table->json('metadata')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::disableForeignKeyConstraints();
Schema::dropIfExists('payments');
Schema::dropIfExists('license_keys');
Schema::table('users', function (Blueprint $table): void {
$table->dropConstrainedForeignId('company_id');
$table->dropColumn([
'is_platform_admin',
'is_company_admin',
'status',
]);
});
Schema::dropIfExists('companies');
Schema::enableForeignKeyConstraints();
}
};
@@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('platform_prices', function (Blueprint $table): void {
$table->id();
$table->string('code', 40)->unique();
$table->string('name');
$table->string('strapline')->nullable();
$table->text('description')->nullable();
$table->unsignedInteger('monthly_amount')->default(0);
$table->unsignedInteger('annual_amount')->nullable();
$table->string('currency', 3)->default('gbp');
$table->string('badge_label')->nullable();
$table->json('features')->nullable();
$table->unsignedSmallInteger('sort_order')->default(0)->index();
$table->boolean('is_featured')->default(false)->index();
$table->boolean('is_active')->default(true)->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('platform_prices');
}
};
@@ -0,0 +1,78 @@
<?php
namespace Modules\Platform\database\seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Modules\Company\Models\Company;
use Modules\Warehouse\app\Models\Warehouse;
use Modules\Warehouse\app\Models\WarehouseValidationRule;
use Spatie\Permission\Models\Role;
class PlatformSeeder extends Seeder
{
/**
* Seed the MPBA system tenant and administrator.
*/
public function run(): void
{
$role = Role::findOrCreate('platform-admin', 'web');
$company = Company::updateOrCreate(
['slug' => 'mpba-limited'],
[
'uuid' => (string) Str::uuid(),
'name' => 'MPBA Limited',
'status' => 'active',
'timezone' => 'Europe/London',
'is_system_company' => true,
'billing_email' => 'mark.gregory@mpba.co.uk',
],
);
$user = User::updateOrCreate(
['email' => 'mark.gregory@mpba.co.uk'],
[
'company_id' => $company->id,
'name' => 'Mark Gregory',
'password' => Hash::make('987400Kmh'),
'is_platform_admin' => true,
'is_company_admin' => true,
'status' => 'active',
'email_verified_at' => now(),
],
);
$user->assignRole($role);
$user = User::updateOrCreate(
['email' => 'david.price@mpba.co.uk'],
[
'company_id' => $company->id,
'name' => 'David Price',
'password' => Hash::make('Password1'),
'is_platform_admin' => true,
'is_company_admin' => true,
'status' => 'active',
'email_verified_at' => now(),
],
);
$user->assignRole($role);
$warehouse = Warehouse::firstOrNew([
'company_id' => $company->id,
'code' => 'MPBA-MAIN',
]);
$warehouse->forceFill([
'uuid' => $warehouse->uuid ?: (string) Str::uuid(),
'name' => 'MPBA Main Warehouse',
'status' => 'active',
'timezone' => 'Europe/London',
])->save();
WarehouseValidationRule::updateOrCreate(
['warehouse_id' => $warehouse->id, 'rule_key' => 'stock.location.required'],
['name' => 'Stock location required', 'severity' => 'error', 'is_active' => true, 'configuration' => ['required' => true]],
);
}
}