-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the two discussion_id -> post_id migrations into 4 total
- Loading branch information
1 parent
aa4f010
commit 2726554
Showing
4 changed files
with
73 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
migrations/2023_07_08_000000_rename_polls_discussion_id_column_1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/polls. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Schema\Builder; | ||
|
||
// Split 2/2 of 2023_07_08_000000_rename_polls_discussion_id_column.php | ||
return [ | ||
'up' => function (Builder $schema) { | ||
// Do not run this migration if the column was already renamed before the split | ||
if ($schema->hasColumn('polls', 'post_id')) { | ||
return; | ||
} | ||
|
||
$schema->table('polls', function (Blueprint $table) { | ||
$table->renameColumn('discussion_id', 'post_id'); | ||
}); | ||
}, | ||
'down' => function (Builder $schema) { | ||
$schema->table('polls', function (Blueprint $table) { | ||
$table->renameColumn('post_id', 'discussion_id'); | ||
}); | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
migrations/2023_07_08_000002_add_polls_post_id_foreign.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/polls. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Illuminate\Database\Query\JoinClause; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Schema\Builder; | ||
use Illuminate\Support\Arr; | ||
|
||
// Split 2/2 of 2023_07_08_000001_update_polls_discussion_relation_to_first_post.php | ||
return [ | ||
'up' => function (Builder $schema) { | ||
// Do not run this migration if the foreign key was already added before the split | ||
$db = $schema->getConnection(); | ||
$foreignKeys = $db->getDoctrineSchemaManager()->listTableForeignKeys("{$db->getTablePrefix()}polls"); | ||
|
||
foreach ($foreignKeys as $foreignKey) { | ||
if (in_array('post_id', $foreignKey->getLocalColumns())) { | ||
return; | ||
} | ||
} | ||
|
||
$schema->table('polls', function (Blueprint $table) { | ||
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); | ||
}); | ||
}, | ||
'down' => function (Builder $schema) { | ||
$schema->table('polls', function (Blueprint $table) { | ||
$table->dropForeign(['post_id']); | ||
}); | ||
}, | ||
]; |