Change precheck order in migrations

This commit is contained in:
Constantin Graf
2024-11-05 12:32:51 +01:00
parent 3b3f593080
commit 95c1bcd4cb

View File

@@ -28,13 +28,6 @@ return new class extends Migration
if ($foreignKeyProblems->count() > 0) { if ($foreignKeyProblems->count() > 0) {
throw new Exception('There are organizations with non-existing owners, check the logs for more information'); throw new Exception('There are organizations with non-existing owners, check the logs for more information');
} }
Schema::table('organizations', function (Blueprint $table): void {
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('restrict')
->onUpdate('cascade');
});
$foreignKeyProblems = DB::table('members') $foreignKeyProblems = DB::table('members')
->select(['members.id', 'members.organization_id']) ->select(['members.id', 'members.organization_id'])
->whereNotExists(function (Builder $query): void { ->whereNotExists(function (Builder $query): void {
@@ -63,6 +56,13 @@ return new class extends Migration
if ($foreignKeyProblems->count() > 0) { if ($foreignKeyProblems->count() > 0) {
throw new Exception('There are members with non-existing users, check the logs for more information'); throw new Exception('There are members with non-existing users, check the logs for more information');
} }
Schema::table('organizations', function (Blueprint $table): void {
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('restrict')
->onUpdate('cascade');
});
Schema::table('members', function (Blueprint $table): void { Schema::table('members', function (Blueprint $table): void {
$table->foreign('organization_id') $table->foreign('organization_id')
->references('id') ->references('id')