From 1a34f61e56f74ed0264203abf21ad67280eba298 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Thu, 3 Jan 2019 20:16:42 +0300 Subject: [PATCH] Fixes #16941: Set `yii\console\controllers\MigrateController::useTablePrefix` to true as default value --- framework/CHANGELOG.md | 1 + .../console/controllers/MigrateController.php | 2 +- .../console/migrate_create/add_columns_fk.php | 90 +++++++++---------- .../migrate_create/add_columns_test.php | 18 ++-- .../console/migrate_create/create_fields.php | 6 +- .../migrate_create/create_foreign_key.php | 78 ++++++++-------- .../console/migrate_create/create_id_pk.php | 6 +- .../console/migrate_create/create_test.php | 6 +- .../migrate_create/create_title_pk.php | 6 +- ...create_title_with_comma_default_values.php | 6 +- .../migrate_create/create_unsigned_big_pk.php | 6 +- .../migrate_create/create_unsigned_pk.php | 6 +- .../migrate_create/drop_columns_test.php | 18 ++-- .../console/migrate_create/drop_fields.php | 6 +- .../drop_products_from_store_table.php | 6 +- .../data/console/migrate_create/drop_test.php | 6 +- .../console/migrate_create/junction_test.php | 54 +++++------ 17 files changed, 161 insertions(+), 160 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 5edea60965..6beda0fda1 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.16 under development ------------------------ +- Chg #16941: Set `yii\console\controllers\MigrateController::useTablePrefix` to true as default value (GHopperMSK) - Bug #16966: Fix ArrayExpression support in related tables (GHopperMSK) - Bug #16891: Fixed Pagination::totalCount initialized incorrectly (taobig) - Bug #16028: Fix serialization of complex cache keys that contain non-UTF sequences (rugabarbo) diff --git a/framework/console/controllers/MigrateController.php b/framework/console/controllers/MigrateController.php index 6909c75774..e4bc45b52a 100644 --- a/framework/console/controllers/MigrateController.php +++ b/framework/console/controllers/MigrateController.php @@ -112,7 +112,7 @@ class MigrateController extends BaseMigrateController * name is `post` the generator wil return `{{%post}}`. * @since 2.0.8 */ - public $useTablePrefix = false; + public $useTablePrefix = true; /** * @var array column definition strings used for creating migration code. * diff --git a/tests/data/console/migrate_create/add_columns_fk.php b/tests/data/console/migrate_create/add_columns_fk.php index b6a610ab3b..07004834bb 100644 --- a/tests/data/console/migrate_create/add_columns_fk.php +++ b/tests/data/console/migrate_create/add_columns_fk.php @@ -11,12 +11,12 @@ return <<addColumn('{table}', 'user_id', \$this->integer()); - \$this->addColumn('{table}', 'product_id', \$this->integer()->unsigned()->notNull()); - \$this->addColumn('{table}', 'order_id', \$this->integer()->notNull()); - \$this->addColumn('{table}', 'created_at', \$this->dateTime()->notNull()); + \$this->addColumn('{{%{table}}}', 'user_id', \$this->integer()); + \$this->addColumn('{{%{table}}}', 'product_id', \$this->integer()->unsigned()->notNull()); + \$this->addColumn('{{%{table}}}', 'order_id', \$this->integer()->notNull()); + \$this->addColumn('{{%{table}}}', 'created_at', \$this->dateTime()->notNull()); // creates index for column `user_id` \$this->createIndex( - 'idx-{table}-user_id', - '{table}', + '{{%idx-{table}-user_id}}', + '{{%{table}}}', 'user_id' ); - // add foreign key for table `user` + // add foreign key for table `{{%user}}` \$this->addForeignKey( - 'fk-{table}-user_id', - '{table}', + '{{%fk-{table}-user_id}}', + '{{%{table}}}', 'user_id', - 'user', + '{{%user}}', 'id', 'CASCADE' ); // creates index for column `product_id` \$this->createIndex( - 'idx-{table}-product_id', - '{table}', + '{{%idx-{table}-product_id}}', + '{{%{table}}}', 'product_id' ); - // add foreign key for table `product` + // add foreign key for table `{{%product}}` \$this->addForeignKey( - 'fk-{table}-product_id', - '{table}', + '{{%fk-{table}-product_id}}', + '{{%{table}}}', 'product_id', - 'product', + '{{%product}}', 'id', 'CASCADE' ); // creates index for column `order_id` \$this->createIndex( - 'idx-{table}-order_id', - '{table}', + '{{%idx-{table}-order_id}}', + '{{%{table}}}', 'order_id' ); - // add foreign key for table `user_order` + // add foreign key for table `{{%user_order}}` \$this->addForeignKey( - 'fk-{table}-order_id', - '{table}', + '{{%fk-{table}-order_id}}', + '{{%{table}}}', 'order_id', - 'user_order', + '{{%user_order}}', 'id', 'CASCADE' ); @@ -87,46 +87,46 @@ class {$class} extends Migration */ public function safeDown() { - // drops foreign key for table `user` + // drops foreign key for table `{{%user}}` \$this->dropForeignKey( - 'fk-{table}-user_id', - '{table}' + '{{%fk-{table}-user_id}}', + '{{%{table}}}' ); // drops index for column `user_id` \$this->dropIndex( - 'idx-{table}-user_id', - '{table}' + '{{%idx-{table}-user_id}}', + '{{%{table}}}' ); - // drops foreign key for table `product` + // drops foreign key for table `{{%product}}` \$this->dropForeignKey( - 'fk-{table}-product_id', - '{table}' + '{{%fk-{table}-product_id}}', + '{{%{table}}}' ); // drops index for column `product_id` \$this->dropIndex( - 'idx-{table}-product_id', - '{table}' + '{{%idx-{table}-product_id}}', + '{{%{table}}}' ); - // drops foreign key for table `user_order` + // drops foreign key for table `{{%user_order}}` \$this->dropForeignKey( - 'fk-{table}-order_id', - '{table}' + '{{%fk-{table}-order_id}}', + '{{%{table}}}' ); // drops index for column `order_id` \$this->dropIndex( - 'idx-{table}-order_id', - '{table}' + '{{%idx-{table}-order_id}}', + '{{%{table}}}' ); - \$this->dropColumn('{table}', 'user_id'); - \$this->dropColumn('{table}', 'product_id'); - \$this->dropColumn('{table}', 'order_id'); - \$this->dropColumn('{table}', 'created_at'); + \$this->dropColumn('{{%{table}}}', 'user_id'); + \$this->dropColumn('{{%{table}}}', 'product_id'); + \$this->dropColumn('{{%{table}}}', 'order_id'); + \$this->dropColumn('{{%{table}}}', 'created_at'); } } diff --git a/tests/data/console/migrate_create/add_columns_test.php b/tests/data/console/migrate_create/add_columns_test.php index 487ccc28c3..c2c4f9492b 100644 --- a/tests/data/console/migrate_create/add_columns_test.php +++ b/tests/data/console/migrate_create/add_columns_test.php @@ -11,7 +11,7 @@ return <<addColumn('{table}', 'title', \$this->string(10)->notNull()); - \$this->addColumn('{table}', 'body', \$this->text()->notNull()); - \$this->addColumn('{table}', 'price', \$this->money(11,2)->notNull()); - \$this->addColumn('{table}', 'created_at', \$this->dateTime()); + \$this->addColumn('{{%{table}}}', 'title', \$this->string(10)->notNull()); + \$this->addColumn('{{%{table}}}', 'body', \$this->text()->notNull()); + \$this->addColumn('{{%{table}}}', 'price', \$this->money(11,2)->notNull()); + \$this->addColumn('{{%{table}}}', 'created_at', \$this->dateTime()); } /** @@ -31,10 +31,10 @@ class {$class} extends Migration */ public function safeDown() { - \$this->dropColumn('{table}', 'title'); - \$this->dropColumn('{table}', 'body'); - \$this->dropColumn('{table}', 'price'); - \$this->dropColumn('{table}', 'created_at'); + \$this->dropColumn('{{%{table}}}', 'title'); + \$this->dropColumn('{{%{table}}}', 'body'); + \$this->dropColumn('{{%{table}}}', 'price'); + \$this->dropColumn('{{%{table}}}', 'created_at'); } } diff --git a/tests/data/console/migrate_create/create_fields.php b/tests/data/console/migrate_create/create_fields.php index 1f782e60de..f6bbcb7d3e 100644 --- a/tests/data/console/migrate_create/create_fields.php +++ b/tests/data/console/migrate_create/create_fields.php @@ -11,7 +11,7 @@ return <<createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'id' => \$this->primaryKey(), 'title' => \$this->string(10)->notNull()->unique()->defaultValue("test"), 'body' => \$this->text()->notNull(), @@ -34,7 +34,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } } diff --git a/tests/data/console/migrate_create/create_foreign_key.php b/tests/data/console/migrate_create/create_foreign_key.php index 9e00e212a5..86004ee7c4 100644 --- a/tests/data/console/migrate_create/create_foreign_key.php +++ b/tests/data/console/migrate_create/create_foreign_key.php @@ -11,12 +11,12 @@ return <<createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'id' => \$this->primaryKey(), 'user_id' => \$this->integer(), 'product_id' => \$this->integer()->unsigned()->notNull(), @@ -35,51 +35,51 @@ class {$class} extends Migration // creates index for column `user_id` \$this->createIndex( - 'idx-{table}-user_id', - '{table}', + '{{%idx-{table}-user_id}}', + '{{%{table}}}', 'user_id' ); - // add foreign key for table `user` + // add foreign key for table `{{%user}}` \$this->addForeignKey( - 'fk-{table}-user_id', - '{table}', + '{{%fk-{table}-user_id}}', + '{{%{table}}}', 'user_id', - 'user', + '{{%user}}', 'id', 'CASCADE' ); // creates index for column `product_id` \$this->createIndex( - 'idx-{table}-product_id', - '{table}', + '{{%idx-{table}-product_id}}', + '{{%{table}}}', 'product_id' ); - // add foreign key for table `product` + // add foreign key for table `{{%product}}` \$this->addForeignKey( - 'fk-{table}-product_id', - '{table}', + '{{%fk-{table}-product_id}}', + '{{%{table}}}', 'product_id', - 'product', + '{{%product}}', 'id', 'CASCADE' ); // creates index for column `order_id` \$this->createIndex( - 'idx-{table}-order_id', - '{table}', + '{{%idx-{table}-order_id}}', + '{{%{table}}}', 'order_id' ); - // add foreign key for table `user_order` + // add foreign key for table `{{%user_order}}` \$this->addForeignKey( - 'fk-{table}-order_id', - '{table}', + '{{%fk-{table}-order_id}}', + '{{%{table}}}', 'order_id', - 'user_order', + '{{%user_order}}', 'id', 'CASCADE' ); @@ -90,43 +90,43 @@ class {$class} extends Migration */ public function safeDown() { - // drops foreign key for table `user` + // drops foreign key for table `{{%user}}` \$this->dropForeignKey( - 'fk-{table}-user_id', - '{table}' + '{{%fk-{table}-user_id}}', + '{{%{table}}}' ); // drops index for column `user_id` \$this->dropIndex( - 'idx-{table}-user_id', - '{table}' + '{{%idx-{table}-user_id}}', + '{{%{table}}}' ); - // drops foreign key for table `product` + // drops foreign key for table `{{%product}}` \$this->dropForeignKey( - 'fk-{table}-product_id', - '{table}' + '{{%fk-{table}-product_id}}', + '{{%{table}}}' ); // drops index for column `product_id` \$this->dropIndex( - 'idx-{table}-product_id', - '{table}' + '{{%idx-{table}-product_id}}', + '{{%{table}}}' ); - // drops foreign key for table `user_order` + // drops foreign key for table `{{%user_order}}` \$this->dropForeignKey( - 'fk-{table}-order_id', - '{table}' + '{{%fk-{table}-order_id}}', + '{{%{table}}}' ); // drops index for column `order_id` \$this->dropIndex( - 'idx-{table}-order_id', - '{table}' + '{{%idx-{table}-order_id}}', + '{{%{table}}}' ); - \$this->dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } } diff --git a/tests/data/console/migrate_create/create_id_pk.php b/tests/data/console/migrate_create/create_id_pk.php index da61b5d2d6..f46c905444 100644 --- a/tests/data/console/migrate_create/create_id_pk.php +++ b/tests/data/console/migrate_create/create_id_pk.php @@ -11,7 +11,7 @@ return <<createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'id' => \$this->primaryKey(), 'address' => \$this->string(), 'address2' => \$this->string(), @@ -33,7 +33,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } } diff --git a/tests/data/console/migrate_create/create_test.php b/tests/data/console/migrate_create/create_test.php index 19453462c8..530aa2de4a 100644 --- a/tests/data/console/migrate_create/create_test.php +++ b/tests/data/console/migrate_create/create_test.php @@ -11,7 +11,7 @@ return <<createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'id' => \$this->primaryKey(), ]); } @@ -30,7 +30,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } } diff --git a/tests/data/console/migrate_create/create_title_pk.php b/tests/data/console/migrate_create/create_title_pk.php index 1c125ef6cb..bbd6b8a48b 100644 --- a/tests/data/console/migrate_create/create_title_pk.php +++ b/tests/data/console/migrate_create/create_title_pk.php @@ -11,7 +11,7 @@ return <<createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'title' => \$this->primaryKey(), 'body' => \$this->text()->notNull(), 'price' => \$this->money(11,2), @@ -32,7 +32,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } } diff --git a/tests/data/console/migrate_create/create_title_with_comma_default_values.php b/tests/data/console/migrate_create/create_title_with_comma_default_values.php index 660014e919..6c0c4fbddc 100644 --- a/tests/data/console/migrate_create/create_title_with_comma_default_values.php +++ b/tests/data/console/migrate_create/create_title_with_comma_default_values.php @@ -11,7 +11,7 @@ return <<createTable('test', [ + \$this->createTable('{{%test}}', [ 'id' => \$this->primaryKey(), 'title' => \$this->string(10)->notNull()->unique()->defaultValue(",te,st"), 'body' => \$this->text()->notNull()->defaultValue(",test"), @@ -33,7 +33,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->dropTable('test'); + \$this->dropTable('{{%test}}'); } } diff --git a/tests/data/console/migrate_create/create_unsigned_big_pk.php b/tests/data/console/migrate_create/create_unsigned_big_pk.php index 9486bf653f..899b40ac68 100644 --- a/tests/data/console/migrate_create/create_unsigned_big_pk.php +++ b/tests/data/console/migrate_create/create_unsigned_big_pk.php @@ -11,7 +11,7 @@ return <<createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'brand_id' => \$this->bigPrimaryKey()->unsigned(), ]); } @@ -30,7 +30,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } } diff --git a/tests/data/console/migrate_create/create_unsigned_pk.php b/tests/data/console/migrate_create/create_unsigned_pk.php index 89948dadbf..ddb87e7737 100644 --- a/tests/data/console/migrate_create/create_unsigned_pk.php +++ b/tests/data/console/migrate_create/create_unsigned_pk.php @@ -11,7 +11,7 @@ return <<createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'brand_id' => \$this->primaryKey()->unsigned(), ]); } @@ -30,7 +30,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } } diff --git a/tests/data/console/migrate_create/drop_columns_test.php b/tests/data/console/migrate_create/drop_columns_test.php index 709ce05acb..2346822bb2 100644 --- a/tests/data/console/migrate_create/drop_columns_test.php +++ b/tests/data/console/migrate_create/drop_columns_test.php @@ -11,7 +11,7 @@ return <<dropColumn('{table}', 'title'); - \$this->dropColumn('{table}', 'body'); - \$this->dropColumn('{table}', 'price'); - \$this->dropColumn('{table}', 'created_at'); + \$this->dropColumn('{{%{table}}}', 'title'); + \$this->dropColumn('{{%{table}}}', 'body'); + \$this->dropColumn('{{%{table}}}', 'price'); + \$this->dropColumn('{{%{table}}}', 'created_at'); } /** @@ -31,10 +31,10 @@ class {$class} extends Migration */ public function safeDown() { - \$this->addColumn('{table}', 'title', \$this->string(10)->notNull()); - \$this->addColumn('{table}', 'body', \$this->text()->notNull()); - \$this->addColumn('{table}', 'price', \$this->money(11,2)->notNull()); - \$this->addColumn('{table}', 'created_at', \$this->dateTime()); + \$this->addColumn('{{%{table}}}', 'title', \$this->string(10)->notNull()); + \$this->addColumn('{{%{table}}}', 'body', \$this->text()->notNull()); + \$this->addColumn('{{%{table}}}', 'price', \$this->money(11,2)->notNull()); + \$this->addColumn('{{%{table}}}', 'created_at', \$this->dateTime()); } } diff --git a/tests/data/console/migrate_create/drop_fields.php b/tests/data/console/migrate_create/drop_fields.php index eeb03b305a..01a51ff11a 100644 --- a/tests/data/console/migrate_create/drop_fields.php +++ b/tests/data/console/migrate_create/drop_fields.php @@ -11,7 +11,7 @@ return <<dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } /** @@ -28,7 +28,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'id' => \$this->primaryKey(), 'body' => \$this->text()->notNull(), 'price' => \$this->money(11,2), diff --git a/tests/data/console/migrate_create/drop_products_from_store_table.php b/tests/data/console/migrate_create/drop_products_from_store_table.php index 69e2e16f70..a53fc80f9c 100644 --- a/tests/data/console/migrate_create/drop_products_from_store_table.php +++ b/tests/data/console/migrate_create/drop_products_from_store_table.php @@ -11,7 +11,7 @@ return <<dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } /** @@ -28,7 +28,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'id' => \$this->primaryKey(), ]); } diff --git a/tests/data/console/migrate_create/drop_test.php b/tests/data/console/migrate_create/drop_test.php index 69e2e16f70..a53fc80f9c 100644 --- a/tests/data/console/migrate_create/drop_test.php +++ b/tests/data/console/migrate_create/drop_test.php @@ -11,7 +11,7 @@ return <<dropTable('{table}'); + \$this->dropTable('{{%{table}}}'); } /** @@ -28,7 +28,7 @@ class {$class} extends Migration */ public function safeDown() { - \$this->createTable('{table}', [ + \$this->createTable('{{%{table}}}', [ 'id' => \$this->primaryKey(), ]); } diff --git a/tests/data/console/migrate_create/junction_test.php b/tests/data/console/migrate_create/junction_test.php index 31ef0f802d..60cd9e4b99 100644 --- a/tests/data/console/migrate_create/junction_test.php +++ b/tests/data/console/migrate_create/junction_test.php @@ -11,11 +11,11 @@ return <<createTable('post_tag', [ + \$this->createTable('{{%post_tag}}', [ 'post_id' => \$this->integer(), 'tag_id' => \$this->integer(), 'PRIMARY KEY(post_id, tag_id)', @@ -32,34 +32,34 @@ class {$class} extends Migration // creates index for column `post_id` \$this->createIndex( - 'idx-post_tag-post_id', - 'post_tag', + '{{%idx-post_tag-post_id}}', + '{{%post_tag}}', 'post_id' ); - // add foreign key for table `post` + // add foreign key for table `{{%post}}` \$this->addForeignKey( - 'fk-post_tag-post_id', - 'post_tag', + '{{%fk-post_tag-post_id}}', + '{{%post_tag}}', 'post_id', - 'post', + '{{%post}}', 'id', 'CASCADE' ); // creates index for column `tag_id` \$this->createIndex( - 'idx-post_tag-tag_id', - 'post_tag', + '{{%idx-post_tag-tag_id}}', + '{{%post_tag}}', 'tag_id' ); - // add foreign key for table `tag` + // add foreign key for table `{{%tag}}` \$this->addForeignKey( - 'fk-post_tag-tag_id', - 'post_tag', + '{{%fk-post_tag-tag_id}}', + '{{%post_tag}}', 'tag_id', - 'tag', + '{{%tag}}', 'id', 'CASCADE' ); @@ -70,31 +70,31 @@ class {$class} extends Migration */ public function safeDown() { - // drops foreign key for table `post` + // drops foreign key for table `{{%post}}` \$this->dropForeignKey( - 'fk-post_tag-post_id', - 'post_tag' + '{{%fk-post_tag-post_id}}', + '{{%post_tag}}' ); // drops index for column `post_id` \$this->dropIndex( - 'idx-post_tag-post_id', - 'post_tag' + '{{%idx-post_tag-post_id}}', + '{{%post_tag}}' ); - // drops foreign key for table `tag` + // drops foreign key for table `{{%tag}}` \$this->dropForeignKey( - 'fk-post_tag-tag_id', - 'post_tag' + '{{%fk-post_tag-tag_id}}', + '{{%post_tag}}' ); // drops index for column `tag_id` \$this->dropIndex( - 'idx-post_tag-tag_id', - 'post_tag' + '{{%idx-post_tag-tag_id}}', + '{{%post_tag}}' ); - \$this->dropTable('post_tag'); + \$this->dropTable('{{%post_tag}}'); } }