forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* method to simplify migrate/create tests * use new assertion for all migration/create tests * move the expected files to test/data/console
- Loading branch information
1 parent
bd2e78c
commit fdbf7d8
Showing
15 changed files
with
962 additions
and
974 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
|
||
return <<<CODE | ||
<?php | ||
use yii\db\Migration; | ||
/** | ||
* Handles adding columns to table `test`. | ||
* Has foreign keys to the tables: | ||
* | ||
* - `user` | ||
* - `product` | ||
* - `user_order` | ||
*/ | ||
class {$class} extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function up() | ||
{ | ||
\$this->addColumn('test', 'user_id', \$this->integer()); | ||
\$this->addColumn('test', 'product_id', \$this->integer()->unsigned()->notNull()); | ||
\$this->addColumn('test', 'order_id', \$this->integer()->notNull()); | ||
\$this->addColumn('test', 'created_at', \$this->dateTime()->notNull()); | ||
// creates index for column `user_id` | ||
\$this->createIndex( | ||
'idx-test-user_id', | ||
'test', | ||
'user_id' | ||
); | ||
// add foreign key for table `user` | ||
\$this->addForeignKey( | ||
'fk-test-user_id', | ||
'test', | ||
'user_id', | ||
'user', | ||
'id', | ||
'CASCADE' | ||
); | ||
// creates index for column `product_id` | ||
\$this->createIndex( | ||
'idx-test-product_id', | ||
'test', | ||
'product_id' | ||
); | ||
// add foreign key for table `product` | ||
\$this->addForeignKey( | ||
'fk-test-product_id', | ||
'test', | ||
'product_id', | ||
'product', | ||
'id', | ||
'CASCADE' | ||
); | ||
// creates index for column `order_id` | ||
\$this->createIndex( | ||
'idx-test-order_id', | ||
'test', | ||
'order_id' | ||
); | ||
// add foreign key for table `user_order` | ||
\$this->addForeignKey( | ||
'fk-test-order_id', | ||
'test', | ||
'order_id', | ||
'user_order', | ||
'id', | ||
'CASCADE' | ||
); | ||
} | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function down() | ||
{ | ||
// drops foreign key for table `user` | ||
\$this->dropForeignKey( | ||
'fk-test-user_id', | ||
'test' | ||
); | ||
// drops index for column `user_id` | ||
\$this->dropIndex( | ||
'idx-test-user_id', | ||
'test' | ||
); | ||
// drops foreign key for table `product` | ||
\$this->dropForeignKey( | ||
'fk-test-product_id', | ||
'test' | ||
); | ||
// drops index for column `product_id` | ||
\$this->dropIndex( | ||
'idx-test-product_id', | ||
'test' | ||
); | ||
// drops foreign key for table `user_order` | ||
\$this->dropForeignKey( | ||
'fk-test-order_id', | ||
'test' | ||
); | ||
// drops index for column `order_id` | ||
\$this->dropIndex( | ||
'idx-test-order_id', | ||
'test' | ||
); | ||
\$this->dropColumn('test', 'user_id'); | ||
\$this->dropColumn('test', 'product_id'); | ||
\$this->dropColumn('test', 'order_id'); | ||
\$this->dropColumn('test', 'created_at'); | ||
} | ||
} | ||
CODE; |
128 changes: 128 additions & 0 deletions
128
tests/data/console/migrate_create/add_columns_prefix.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,128 @@ | ||
<?php | ||
|
||
return <<<CODE | ||
<?php | ||
use yii\db\Migration; | ||
/** | ||
* Handles adding columns to table `{{%test}}`. | ||
* Has foreign keys to the tables: | ||
* | ||
* - `{{%user}}` | ||
* - `{{%product}}` | ||
* - `{{%user_order}}` | ||
*/ | ||
class {$class} extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function up() | ||
{ | ||
\$this->addColumn('{{%test}}', 'user_id', \$this->integer()); | ||
\$this->addColumn('{{%test}}', 'product_id', \$this->integer()->unsigned()->notNull()); | ||
\$this->addColumn('{{%test}}', 'order_id', \$this->integer()->notNull()); | ||
\$this->addColumn('{{%test}}', 'created_at', \$this->dateTime()->notNull()); | ||
// creates index for column `user_id` | ||
\$this->createIndex( | ||
'{{%idx-test-user_id}}', | ||
'{{%test}}', | ||
'user_id' | ||
); | ||
// add foreign key for table `{{%user}}` | ||
\$this->addForeignKey( | ||
'{{%fk-test-user_id}}', | ||
'{{%test}}', | ||
'user_id', | ||
'{{%user}}', | ||
'id', | ||
'CASCADE' | ||
); | ||
// creates index for column `product_id` | ||
\$this->createIndex( | ||
'{{%idx-test-product_id}}', | ||
'{{%test}}', | ||
'product_id' | ||
); | ||
// add foreign key for table `{{%product}}` | ||
\$this->addForeignKey( | ||
'{{%fk-test-product_id}}', | ||
'{{%test}}', | ||
'product_id', | ||
'{{%product}}', | ||
'id', | ||
'CASCADE' | ||
); | ||
// creates index for column `order_id` | ||
\$this->createIndex( | ||
'{{%idx-test-order_id}}', | ||
'{{%test}}', | ||
'order_id' | ||
); | ||
// add foreign key for table `{{%user_order}}` | ||
\$this->addForeignKey( | ||
'{{%fk-test-order_id}}', | ||
'{{%test}}', | ||
'order_id', | ||
'{{%user_order}}', | ||
'id', | ||
'CASCADE' | ||
); | ||
} | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function down() | ||
{ | ||
// drops foreign key for table `{{%user}}` | ||
\$this->dropForeignKey( | ||
'{{%fk-test-user_id}}', | ||
'{{%test}}' | ||
); | ||
// drops index for column `user_id` | ||
\$this->dropIndex( | ||
'{{%idx-test-user_id}}', | ||
'{{%test}}' | ||
); | ||
// drops foreign key for table `{{%product}}` | ||
\$this->dropForeignKey( | ||
'{{%fk-test-product_id}}', | ||
'{{%test}}' | ||
); | ||
// drops index for column `product_id` | ||
\$this->dropIndex( | ||
'{{%idx-test-product_id}}', | ||
'{{%test}}' | ||
); | ||
// drops foreign key for table `{{%user_order}}` | ||
\$this->dropForeignKey( | ||
'{{%fk-test-order_id}}', | ||
'{{%test}}' | ||
); | ||
// drops index for column `order_id` | ||
\$this->dropIndex( | ||
'{{%idx-test-order_id}}', | ||
'{{%test}}' | ||
); | ||
\$this->dropColumn('{{%test}}', 'user_id'); | ||
\$this->dropColumn('{{%test}}', 'product_id'); | ||
\$this->dropColumn('{{%test}}', 'order_id'); | ||
\$this->dropColumn('{{%test}}', 'created_at'); | ||
} | ||
} | ||
CODE; |
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,36 @@ | ||
<?php | ||
|
||
return <<<CODE | ||
<?php | ||
use yii\db\Migration; | ||
/** | ||
* Handles adding columns to table `test`. | ||
*/ | ||
class {$class} extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function up() | ||
{ | ||
\$this->addColumn('test', 'title', \$this->string(10)->notNull()); | ||
\$this->addColumn('test', 'body', \$this->text()->notNull()); | ||
\$this->addColumn('test', 'price', \$this->money(11,2)->notNull()); | ||
\$this->addColumn('test', 'created_at', \$this->dateTime()); | ||
} | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function down() | ||
{ | ||
\$this->dropColumn('test', 'title'); | ||
\$this->dropColumn('test', 'body'); | ||
\$this->dropColumn('test', 'price'); | ||
\$this->dropColumn('test', 'created_at'); | ||
} | ||
} | ||
CODE; |
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,35 @@ | ||
<?php | ||
|
||
return <<<CODE | ||
<?php | ||
use yii\db\Migration; | ||
/** | ||
* Handles the creation for table `test`. | ||
*/ | ||
class {$class} extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function up() | ||
{ | ||
\$this->createTable('test', [ | ||
'id' => \$this->primaryKey(), | ||
'title' => \$this->string(10)->notNull()->unique()->defaultValue("test"), | ||
'body' => \$this->text()->notNull(), | ||
'price' => \$this->money(11,2)->notNull(), | ||
]); | ||
} | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function down() | ||
{ | ||
\$this->dropTable('test'); | ||
} | ||
} | ||
CODE; |
Oops, something went wrong.