Skip to content

Commit 5bb10fa

Browse files
authored
Fix migration errors on form_submissions (#324)
* Fix migration errors on form_submissions * Update migration approach
1 parent 775e7de commit 5bb10fa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

database/migrations/updates/relate_form_submissions_by_handle.php.stub

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use Statamic\Eloquent\Forms\SubmissionModel;
99
return new class extends Migration {
1010
public function up()
1111
{
12+
if (Schema::hasColumn($this->prefix('form_submissions'), 'form')) {
13+
return;
14+
}
15+
1216
Schema::table($this->prefix('form_submissions'), function (Blueprint $table) {
1317
$table->string('form', 30)->nullable()->index()->after('id');
1418
});
@@ -24,7 +28,12 @@ return new class extends Migration {
2428
});
2529

2630
Schema::table($this->prefix('form_submissions'), function (Blueprint $table) {
27-
$table->dropForeign(['form_id']);
31+
collect(Schema::getForeignKeys($this->prefix('form_submissions')))->each(function ($fk) use ($table) {
32+
if (count($fk['columns']) == 1 && in_array('form_id', $fk['columns'])) {
33+
$table->dropForeign(['form_id']);
34+
}
35+
});
36+
2837
$table->dropColumn('form_id');
2938
});
3039
}

0 commit comments

Comments
 (0)