Skip to content

Commit

Permalink
Split the two discussion_id -> post_id migrations into 4 total
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Jul 26, 2023
1 parent aa4f010 commit 50325f1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

// Split 1/2 of 2023_07_08_000000_rename_polls_discussion_id_column.php
return [
'up' => function (Builder $schema) {
$schema->table('polls', function (Blueprint $table) {
$table->dropForeign(['discussion_id']);
$table->renameColumn('discussion_id', 'post_id');
});
},
'down' => function (Builder $schema) {
$schema->table('polls', function (Blueprint $table) {
$table->renameColumn('post_id', 'discussion_id');
$table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade');
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

// Split 1/2 of 2023_07_08_000001_update_polls_discussion_relation_to_first_post.php
return [
'up' => function (Builder $schema) {
$db = $schema->getConnection();
Expand Down Expand Up @@ -61,10 +62,6 @@

$deletingPolls->delete();
});

$schema->table('polls', function (Blueprint $table) {
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
});
},
'down' => function (Builder $schema) {
$db = $schema->getConnection();
Expand All @@ -82,9 +79,5 @@
->join('posts', 'polls.post_id', '=', 'posts.id')
->update(['polls.post_id' => $db->raw("{$prefix}posts.discussion_id")]);
});

$schema->table('polls', function (Blueprint $table) {
$table->dropForeign(['post_id']);
});
},
];

0 comments on commit 50325f1

Please sign in to comment.