refactor: consolidate billing migrations into original files
Instead of separate alter-table migrations, edit the original create_table migrations directly since we're resetting the database. - Users table: removed stripe_id, pm_type, pm_last_four, trial_ends_at - Workspaces table: added plan_id, stripe_id, pm_type, pm_last_four, trial_ends_at - Subscriptions table: changed user_id FK to workspace_id FK - Social accounts table: added brand_id FK - Plans and brands tables ordered before their dependents - Deleted 5 redundant alter-table migrations
This commit is contained in:
parent
c867faa2ee
commit
42d5adeb1a
16 changed files with 8 additions and 166 deletions
|
|
@ -29,10 +29,6 @@ public function up(): void
|
|||
$table->text('two_factor_secret')->nullable();
|
||||
$table->text('two_factor_recovery_codes')->nullable();
|
||||
$table->timestamp('two_factor_confirmed_at')->nullable();
|
||||
$table->string('stripe_id')->nullable()->index();
|
||||
$table->string('pm_type')->nullable();
|
||||
$table->string('pm_last_four', 4)->nullable();
|
||||
$table->timestamp('trial_ends_at')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->string('setup')->nullable();
|
||||
$table->string('persona')->nullable();
|
||||
|
|
|
|||
|
|
@ -16,8 +16,13 @@ public function up(): void
|
|||
Schema::create('workspaces', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->uuid('user_id');
|
||||
$table->foreignUuid('plan_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('timezone');
|
||||
$table->string('stripe_id')->nullable()->index();
|
||||
$table->string('pm_type')->nullable();
|
||||
$table->string('pm_last_four')->nullable();
|
||||
$table->timestamp('trial_ends_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public function up(): void
|
|||
{
|
||||
Schema::create('subscriptions', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignUuid('workspace_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('type');
|
||||
$table->string('stripe_id')->unique();
|
||||
$table->string('stripe_status');
|
||||
|
|
@ -25,7 +25,7 @@ public function up(): void
|
|||
$table->timestamp('ends_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['user_id', 'stripe_status']);
|
||||
$table->index(['workspace_id', 'stripe_status']);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -16,6 +16,7 @@ public function up(): void
|
|||
Schema::create('social_accounts', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->uuid('workspace_id');
|
||||
$table->foreignUuid('brand_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('platform');
|
||||
$table->string('platform_user_id');
|
||||
$table->string('username')->nullable();
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('social_accounts', function (Blueprint $table) {
|
||||
$table->foreignUuid('brand_id')->nullable()->after('workspace_id')->constrained()->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('social_accounts', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('brand_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('workspaces', function (Blueprint $table) {
|
||||
$table->foreignUuid('plan_id')->nullable()->after('user_id')->constrained()->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('workspaces', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('plan_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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::table('workspaces', function (Blueprint $table) {
|
||||
$table->string('stripe_id')->nullable()->after('plan_id')->index();
|
||||
$table->string('pm_type')->nullable()->after('stripe_id');
|
||||
$table->string('pm_last_four')->nullable()->after('pm_type');
|
||||
$table->timestamp('trial_ends_at')->nullable()->after('pm_last_four');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('workspaces', function (Blueprint $table) {
|
||||
$table->dropIndex(['stripe_id']);
|
||||
$table->dropColumn(['stripe_id', 'pm_type', 'pm_last_four', 'trial_ends_at']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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::table('subscriptions', function (Blueprint $table) {
|
||||
$table->dropIndex(['user_id', 'stripe_status']);
|
||||
$table->dropForeign(['user_id']);
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('subscriptions', function (Blueprint $table) {
|
||||
$table->foreignUuid('workspace_id')->after('id')->constrained()->cascadeOnDelete();
|
||||
$table->index(['workspace_id', 'stripe_status']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('subscriptions', function (Blueprint $table) {
|
||||
$table->dropIndex(['workspace_id', 'stripe_status']);
|
||||
$table->dropForeign(['workspace_id']);
|
||||
$table->dropColumn('workspace_id');
|
||||
});
|
||||
|
||||
Schema::table('subscriptions', function (Blueprint $table) {
|
||||
$table->foreignUuid('user_id')->after('id')->constrained()->cascadeOnDelete();
|
||||
$table->index(['user_id', 'stripe_status']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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::table('users', function (Blueprint $table) {
|
||||
$table->dropIndex(['stripe_id']);
|
||||
$table->dropColumn(['stripe_id', 'pm_type', 'pm_last_four', 'trial_ends_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('stripe_id')->nullable()->index();
|
||||
$table->string('pm_type')->nullable();
|
||||
$table->string('pm_last_four', 4)->nullable();
|
||||
$table->timestamp('trial_ends_at')->nullable();
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue