From aca0f3c57a556689ef70c695ca2477d535dc5128 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 19 Jul 2018 10:36:46 +0200 Subject: [PATCH] added constraints, discussions_first_post_id_foreign blocks here --- ...093900_change_access_tokens_b8_columns.php | 4 +++ ...1_155200_change_discussions_b8_columns.php | 11 +++++++ ...00_change_discussions_users_b8_columns.php | 5 +++ ..._072600_change_email_tokens_b8_columns.php | 31 +++++++++++++++++++ ...change_email_tokens_rename_id_to_token.php | 14 --------- ...133000_change_notifications_b8_columns.php | 4 +++ ...8_01_18_135000_change_posts_b8_columns.php | 10 ++++++ ...18_07_19_101300_constraints_group_user.php | 28 +++++++++++++++++ ..._101301_constraints_groups_permissions.php | 27 ++++++++++++++++ ..._19_101301_constraints_password_tokens.php | 27 ++++++++++++++++ 10 files changed, 147 insertions(+), 14 deletions(-) create mode 100644 framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php delete mode 100644 framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php create mode 100644 framework/core/migrations/2018_07_19_101300_constraints_group_user.php create mode 100644 framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php create mode 100644 framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php diff --git a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php b/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php index 9fd9df5fb..823c827d4 100644 --- a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php +++ b/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php @@ -19,6 +19,8 @@ return [ $table->renameColumn('lifetime', 'lifetime_seconds'); $table->renameColumn('last_activity', 'last_activity_at'); $table->dateTime('created_at'); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); }, @@ -28,6 +30,8 @@ return [ $table->renameColumn('last_activity_at', 'last_activity'); $table->dropColumn('created_at'); $table->renameColumn('token', 'id'); + + $table->dropForeign('access_tokens_user_id_foreign'); }); } ]; diff --git a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php index c88fa528a..5ef86a15d 100644 --- a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php +++ b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php @@ -25,6 +25,12 @@ return [ $table->renameColumn('last_user_id', 'last_posted_user_id'); $table->renameColumn('hide_time', 'hidden_at'); $table->renameColumn('hide_user_id', 'hidden_user_id'); + + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('last_posted_user_id')->references('id')->on('users'); + $table->foreign('hidden_user_id')->references('id')->on('users'); + $table->foreign('first_post_id')->references('id')->on('posts'); + $table->foreign('last_post_id')->references('id')->on('posts'); }); }, @@ -40,6 +46,11 @@ return [ $table->renameColumn('last_posted_user_id', 'last_user_id'); $table->renameColumn('hidden_at', 'hide_time'); $table->renameColumn('hidden_user_id', 'hide_user_id'); + + $table->dropForeign([ + 'discussions_user_id_foreign', 'discussions_last_posted_user_id', 'hidden_user_id', + 'first_post_id', 'last_post_id' + ]); }); } ]; diff --git a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php index 5797a033f..1fc3ccd43 100644 --- a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php +++ b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php @@ -17,6 +17,9 @@ return [ $schema->table('discussions_users', function (Blueprint $table) { $table->renameColumn('read_time', 'last_read_at'); $table->renameColumn('read_number', 'last_read_post_number'); + + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); }); }, @@ -24,6 +27,8 @@ return [ $schema->table('discussions_users', function (Blueprint $table) { $table->renameColumn('last_read_at', 'read_time'); $table->renameColumn('last_read_post_number', 'read_number'); + + $table->dropForeign(['discussions_users_user_id_foreign', 'discussions_users_discussion_id_foreign']); }); } ]; diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php new file mode 100644 index 000000000..aa8153b22 --- /dev/null +++ b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php @@ -0,0 +1,31 @@ + + * + * 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) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->renameColumn('id', 'token'); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->renameColumn('token', 'id'); + + $table->dropForeign('email_tokens_user_id_foreign'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php deleted file mode 100644 index 64586a4aa..000000000 --- a/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php +++ /dev/null @@ -1,14 +0,0 @@ - - * - * 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('email_tokens', 'id', 'token'); diff --git a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php b/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php index 2261b0248..aa3e739e6 100644 --- a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php +++ b/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php @@ -21,6 +21,8 @@ return [ $table->timestamp('read_at')->nullable(); $table->timestamp('deleted_at')->nullable(); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); $schema->getConnection()->table('notifications') @@ -46,6 +48,8 @@ return [ $table->boolean('is_read'); $table->boolean('is_deleted'); + + $table->dropForeign('notifications_user_id_foreign'); }); $schema->getConnection()->table('notifications') diff --git a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php index 406210a81..659699a71 100644 --- a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php +++ b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php @@ -23,6 +23,11 @@ return [ $table->renameColumn('hide_user_id', 'hidden_user_id'); $table->longText('content')->change(); + + $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('edited_user_id')->references('id')->on('users'); + $table->foreign('hidden_user_id')->references('id')->on('users'); }); }, @@ -36,6 +41,11 @@ return [ $table->renameColumn('edited_user_id', 'hidden_user_id'); $table->mediumText('content')->change(); + + $table->dropForeign([ + 'posts_user_id_foreign', 'posts_discussion_id_foreign', + 'posts_edited_user_id_foreign', 'posts_hidden_user_id_foreign' + ]); }); } ]; diff --git a/framework/core/migrations/2018_07_19_101300_constraints_group_user.php b/framework/core/migrations/2018_07_19_101300_constraints_group_user.php new file mode 100644 index 000000000..1f2b60564 --- /dev/null +++ b/framework/core/migrations/2018_07_19_101300_constraints_group_user.php @@ -0,0 +1,28 @@ + + * + * 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) { + $schema->table('group_user', function (Blueprint $table) { + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('group_user', function (Blueprint $table) { + $table->dropForeign(['group_user_user_id_foreign', 'group_user_group_id_foreign']); + }); + } +]; diff --git a/framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php b/framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php new file mode 100644 index 000000000..2e46377b6 --- /dev/null +++ b/framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php @@ -0,0 +1,27 @@ + + * + * 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) { + $schema->table('groups_permissions', function (Blueprint $table) { + $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('group_user', function (Blueprint $table) { + $table->dropForeign('group_user_group_id_foreign'); + }); + } +]; diff --git a/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php b/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php new file mode 100644 index 000000000..d4b5e530d --- /dev/null +++ b/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php @@ -0,0 +1,27 @@ + + * + * 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) { + $schema->table('password_tokens', function (Blueprint $table) { + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('password_tokens', function (Blueprint $table) { + $table->dropForeign('password_tokens_user_id_foreign'); + }); + } +];