fixed migration
This commit is contained in:
@@ -2,15 +2,15 @@
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
// Packages table
|
||||
if (!Schema::hasTable('packages')) {
|
||||
if (! Schema::hasTable('packages')) {
|
||||
Schema::create('packages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
@@ -86,7 +86,7 @@ return new class extends Migration
|
||||
}
|
||||
|
||||
// Event Packages
|
||||
if (!Schema::hasTable('event_packages')) {
|
||||
if (! Schema::hasTable('event_packages')) {
|
||||
Schema::create('event_packages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('event_id')->constrained()->cascadeOnDelete();
|
||||
@@ -100,7 +100,7 @@ return new class extends Migration
|
||||
}
|
||||
|
||||
// Tenant Packages
|
||||
if (!Schema::hasTable('tenant_packages')) {
|
||||
if (! Schema::hasTable('tenant_packages')) {
|
||||
Schema::create('tenant_packages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
|
||||
@@ -116,7 +116,7 @@ return new class extends Migration
|
||||
}
|
||||
|
||||
// Package Purchases
|
||||
if (!Schema::hasTable('package_purchases')) {
|
||||
if (! Schema::hasTable('package_purchases')) {
|
||||
Schema::create('package_purchases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->nullable()->constrained();
|
||||
@@ -136,11 +136,11 @@ return new class extends Migration
|
||||
}
|
||||
|
||||
// Purchase History
|
||||
if (!Schema::hasTable('purchase_history')) {
|
||||
if (! Schema::hasTable('purchase_history')) {
|
||||
Schema::create('purchase_history', function (Blueprint $table) {
|
||||
$table->string('id', 255)->primary();
|
||||
$table->string('tenant_id', 255);
|
||||
$table->string('package_id', 255);
|
||||
$table->bigIncrements('id');
|
||||
$table->foreignId('tenant_id')->constrained('tenants');
|
||||
$table->unsignedBigInteger('package_id');
|
||||
$table->integer('credits_added')->default(0);
|
||||
$table->decimal('price', 10, 2)->default(0);
|
||||
$table->string('currency', 3)->default('EUR');
|
||||
@@ -148,31 +148,30 @@ return new class extends Migration
|
||||
$table->string('transaction_id', 255)->nullable();
|
||||
$table->timestamp('purchased_at')->useCurrent();
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->foreign('tenant_id')->references('id')->on('tenants');
|
||||
$table->index('tenant_id');
|
||||
$table->index('purchased_at');
|
||||
$table->index('transaction_id');
|
||||
$table->foreign('package_id')->references('id')->on('packages');
|
||||
});
|
||||
}
|
||||
|
||||
// Add subscription fields to tenants if missing
|
||||
if (Schema::hasTable('tenants')) {
|
||||
if (!Schema::hasColumn('tenants', 'subscription_tier')) {
|
||||
if (! Schema::hasColumn('tenants', 'subscription_tier')) {
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
$table->string('subscription_tier')->default('free')->after('event_credits_balance');
|
||||
});
|
||||
}
|
||||
if (!Schema::hasColumn('tenants', 'subscription_status')) {
|
||||
if (! Schema::hasColumn('tenants', 'subscription_status')) {
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
$table->enum('subscription_status', ['free', 'active', 'suspended', 'expired'])->default('free')->after('subscription_tier');
|
||||
});
|
||||
}
|
||||
if (!Schema::hasColumn('tenants', 'subscription_expires_at')) {
|
||||
if (! Schema::hasColumn('tenants', 'subscription_expires_at')) {
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
$table->timestamp('subscription_expires_at')->nullable()->after('subscription_status');
|
||||
});
|
||||
}
|
||||
if (!Schema::hasColumn('tenants', 'total_revenue')) {
|
||||
if (! Schema::hasColumn('tenants', 'total_revenue')) {
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
$table->decimal('total_revenue', 10, 2)->default(0.00)->after('subscription_expires_at');
|
||||
});
|
||||
@@ -275,7 +274,7 @@ return new class extends Migration
|
||||
{
|
||||
if (app()->environment('local', 'testing')) {
|
||||
// Reverse drops and adds
|
||||
if (!Schema::hasTable('purchase_history')) {
|
||||
if (! Schema::hasTable('purchase_history')) {
|
||||
Schema::create('purchase_history', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
|
||||
@@ -286,7 +285,7 @@ return new class extends Migration
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
if (!Schema::hasTable('event_purchases')) {
|
||||
if (! Schema::hasTable('event_purchases')) {
|
||||
Schema::create('event_purchases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
|
||||
@@ -301,7 +300,7 @@ return new class extends Migration
|
||||
$table->index(['tenant_id', 'purchased_at']);
|
||||
});
|
||||
}
|
||||
if (!Schema::hasTable('event_credits_ledger')) {
|
||||
if (! Schema::hasTable('event_credits_ledger')) {
|
||||
Schema::create('event_credits_ledger', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
|
||||
@@ -316,10 +315,10 @@ return new class extends Migration
|
||||
|
||||
// Re-add old fields to tenants
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('tenants', 'event_credits_balance')) {
|
||||
if (! Schema::hasColumn('tenants', 'event_credits_balance')) {
|
||||
$table->integer('event_credits_balance')->default(1);
|
||||
}
|
||||
if (!Schema::hasColumn('tenants', 'free_event_granted_at')) {
|
||||
if (! Schema::hasColumn('tenants', 'free_event_granted_at')) {
|
||||
$table->timestamp('free_event_granted_at')->nullable();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user