added full module support
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?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::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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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\Platform\app\Models\Company;
|
||||
use Modules\Warehouse\app\Models\Warehouse;
|
||||
use Modules\Warehouse\app\Models\WarehouseValidationRule;
|
||||
|
||||
class PlatformSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the MPBA system tenant and administrator.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$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::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(),
|
||||
]
|
||||
);
|
||||
|
||||
$warehouse = Warehouse::updateOrCreate(
|
||||
['company_id' => $company->id, 'code' => 'MPBA-MAIN'],
|
||||
['name' => 'MPBA Main Warehouse', 'status' => 'active', 'timezone' => 'Europe/London']
|
||||
);
|
||||
|
||||
WarehouseValidationRule::updateOrCreate(
|
||||
['warehouse_id' => $warehouse->id, 'rule_key' => 'stock.location.required'],
|
||||
['name' => 'Stock location required', 'severity' => 'error', 'is_active' => true, 'configuration' => ['required' => true]]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user