added full module support

This commit is contained in:
Mark Gregory
2026-06-10 12:42:07 +01:00
parent 12d4eec076
commit c59b16d791
63 changed files with 1639 additions and 131 deletions
@@ -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');
}
};