removed all references to credits. now credits are completely replaced by addons.
This commit is contained in:
@@ -141,7 +141,6 @@ return new class extends Migration
|
||||
$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');
|
||||
$table->string('platform', 50);
|
||||
@@ -158,7 +157,7 @@ return new class extends Migration
|
||||
if (Schema::hasTable('tenants')) {
|
||||
if (! Schema::hasColumn('tenants', 'subscription_tier')) {
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
$table->string('subscription_tier')->default('free')->after('event_credits_balance');
|
||||
$table->string('subscription_tier')->default('free')->after('email');
|
||||
});
|
||||
}
|
||||
if (! Schema::hasColumn('tenants', 'subscription_status')) {
|
||||
@@ -178,82 +177,8 @@ return new class extends Migration
|
||||
}
|
||||
}
|
||||
|
||||
// Idempotent migration from credits to packages (only if old tables exist and new don't have data)
|
||||
if (Schema::hasTable('event_credits_ledger') && DB::table('tenant_packages')->count() == 0) {
|
||||
// Migrate tenant credits to tenant_packages (Free package)
|
||||
$freePackageId = DB::table('packages')->where('name', 'Free/Test')->value('id');
|
||||
if ($freePackageId) {
|
||||
DB::table('tenants')->where('event_credits_balance', '>', 0)->chunk(100, function ($tenants) use ($freePackageId) {
|
||||
foreach ($tenants as $tenant) {
|
||||
DB::table('tenant_packages')->insertOrIgnore([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $freePackageId,
|
||||
'price' => 0.00,
|
||||
'purchased_at' => $tenant->free_event_granted_at ?? now(),
|
||||
'expires_at' => now()->addDays(30),
|
||||
'used_events' => min($tenant->event_credits_balance, 1),
|
||||
'active' => true,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('package_purchases')->insertOrIgnore([
|
||||
'tenant_id' => $tenant->id,
|
||||
'event_id' => null,
|
||||
'package_id' => $freePackageId,
|
||||
'provider_id' => 'migration_free',
|
||||
'price' => 0.00,
|
||||
'type' => 'reseller_subscription',
|
||||
'metadata' => json_encode(['migrated_from_credits' => $tenant->event_credits_balance]),
|
||||
'ip_address' => null,
|
||||
'user_agent' => null,
|
||||
'refunded' => false,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
// Migrate event purchases if old data exists
|
||||
if (Schema::hasTable('event_purchases')) {
|
||||
DB::table('event_purchases')->join('events', 'event_purchases.event_id', '=', 'events.id')->chunk(100, function ($purchases) use ($freePackageId) {
|
||||
foreach ($purchases as $purchase) {
|
||||
DB::table('event_packages')->insertOrIgnore([
|
||||
'event_id' => $purchase->event_id,
|
||||
'package_id' => $freePackageId,
|
||||
'purchased_price' => $purchase->amount ?? 0.00,
|
||||
'purchased_at' => $purchase->purchased_at ?? now(),
|
||||
'used_photos' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('package_purchases')->insertOrIgnore([
|
||||
'tenant_id' => $purchase->tenant_id,
|
||||
'event_id' => $purchase->event_id,
|
||||
'package_id' => $freePackageId,
|
||||
'provider_id' => $purchase->provider ?? 'migration',
|
||||
'price' => $purchase->amount ?? 0.00,
|
||||
'type' => 'endcustomer_event',
|
||||
'metadata' => json_encode(['migrated_from_event_purchases' => true]),
|
||||
'ip_address' => null,
|
||||
'user_agent' => null,
|
||||
'refunded' => false,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Conditional drop of old credits tables and fields (only if migration happened or old structures exist)
|
||||
if (Schema::hasTable('event_credits_ledger')) {
|
||||
Schema::dropIfExists('event_credits_ledger');
|
||||
}
|
||||
// Keep legacy event_purchases table for compatibility with existing flows/resources.
|
||||
if (Schema::hasTable('purchase_history') && DB::table('package_purchases')->count() > 0) { // Only drop if new data exists
|
||||
Schema::dropIfExists('event_credits_ledger');
|
||||
if (Schema::hasTable('purchase_history') && DB::table('package_purchases')->count() > 0) {
|
||||
Schema::dropIfExists('purchase_history');
|
||||
}
|
||||
|
||||
@@ -279,7 +204,6 @@ return new class extends Migration
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('package_id', 255);
|
||||
$table->integer('credits_added')->default(0);
|
||||
$table->decimal('price', 10, 2)->default(0);
|
||||
$table->string('provider_id');
|
||||
$table->timestamps();
|
||||
|
||||
Reference in New Issue
Block a user