-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement database changes * Split foreign keys in to their own migrations; rename pivot tables * Use whereColumn * Update core attribute names
- Loading branch information
1 parent
eb5592c
commit f18556d
Showing
13 changed files
with
146 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
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
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
14 changes: 14 additions & 0 deletions
14
migrations/2018_06_27_102000_rename_mentions_posts_to_post_mentions_post.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,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Flarum\Database\Migration; | ||
|
||
return Migration::renameTable('mentions_posts', 'post_mentions_post'); |
14 changes: 14 additions & 0 deletions
14
migrations/2018_06_27_102100_rename_mentions_users_to_post_mentions_user.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,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Flarum\Database\Migration; | ||
|
||
return Migration::renameTable('mentions_users', 'post_mentions_user'); |
14 changes: 14 additions & 0 deletions
14
...ns/2018_06_27_102200_change_post_mentions_post_rename_mentions_id_to_mentions_post_id.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,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Flarum\Database\Migration; | ||
|
||
return Migration::renameColumn('post_mentions_post', 'mentions_id', 'mentions_post_id'); |
40 changes: 40 additions & 0 deletions
40
migrations/2018_06_27_102300_change_post_mentions_post_add_foreign_keys.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,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <[email protected]> | ||
* | ||
* 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; | ||
|
||
return [ | ||
'up' => function (Builder $schema) { | ||
// Delete rows with non-existent entities so that we will be able to create | ||
// foreign keys without any issues. | ||
$schema->getConnection() | ||
->table('post_mentions_post') | ||
->whereNotExists(function ($query) { | ||
$query->selectRaw(1)->from('posts')->whereColumn('id', 'post_id'); | ||
}) | ||
->orWhereNotExists(function ($query) { | ||
$query->selectRaw(1)->from('posts')->whereColumn('id', 'mentions_post_id'); | ||
}) | ||
->delete(); | ||
|
||
$schema->table('post_mentions_post', function (Blueprint $table) { | ||
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); | ||
$table->foreign('mentions_post_id')->references('id')->on('posts')->onDelete('cascade'); | ||
}); | ||
}, | ||
|
||
'down' => function (Builder $schema) { | ||
$schema->table('posts_mentions_posts', function (Blueprint $table) { | ||
$table->dropForeign(['post_id', 'mentions_post_id']); | ||
}); | ||
} | ||
]; |
14 changes: 14 additions & 0 deletions
14
...ns/2018_06_27_102400_change_post_mentions_user_rename_mentions_id_to_mentions_user_id.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,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Flarum\Database\Migration; | ||
|
||
return Migration::renameColumn('post_mentions_user', 'mentions_id', 'mentions_user_id'); |
40 changes: 40 additions & 0 deletions
40
migrations/2018_06_27_102500_change_post_mentions_user_add_foreign_keys.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,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <[email protected]> | ||
* | ||
* 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; | ||
|
||
return [ | ||
'up' => function (Builder $schema) { | ||
// Delete rows with non-existent entities so that we will be able to create | ||
// foreign keys without any issues. | ||
$schema->getConnection() | ||
->table('post_mentions_user') | ||
->whereNotExists(function ($query) { | ||
$query->selectRaw(1)->from('posts')->whereColumn('id', 'post_id'); | ||
}) | ||
->orWhereNotExists(function ($query) { | ||
$query->selectRaw(1)->from('users')->whereColumn('id', 'mentions_user_id'); | ||
}) | ||
->delete(); | ||
|
||
$schema->table('post_mentions_user', function (Blueprint $table) { | ||
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); | ||
$table->foreign('mentions_user_id')->references('id')->on('users')->onDelete('cascade'); | ||
}); | ||
}, | ||
|
||
'down' => function (Builder $schema) { | ||
$schema->table('post_mentions_user', function (Blueprint $table) { | ||
$table->dropForeign(['post_id', 'mentions_user_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
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
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
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