From 998cb00185910001476289443edd9726adae1676 Mon Sep 17 00:00:00 2001 From: Yves P Date: Fri, 20 Nov 2015 23:06:14 +0100 Subject: [PATCH] Refactor snapshot baking tests Some tests were split because of a feature added in a release of CakePHP 3.0.X. Since we require 3.1.0 as a minimum requirement now, those tests can be done in one test. --- tests/TestCase/MigrationsTest.php | 3 - .../Shell/Task/MigrationSnapshotTaskTest.php | 27 -- .../test_auto_id_disabled_snapshot_pgsql.php | 54 +++ ...t_composite_constraints_snapshot_pgsql.php | 322 ------------------ .../pgsql/test_not_empty_snapshot_pgsql.php | 47 +++ .../test_auto_id_disabled_snapshot_sqlite.php | 54 +++ ..._composite_constraints_snapshot_sqlite.php | 321 ----------------- .../sqlite/test_not_empty_snapshot_sqlite.php | 47 +++ .../test_auto_id_disabled_snapshot.php | 54 +++ .../test_composite_constraints_snapshot.php | 322 ------------------ .../Migration/test_not_empty_snapshot.php | 47 +++ 11 files changed, 303 insertions(+), 995 deletions(-) delete mode 100644 tests/comparisons/Migration/pgsql/test_composite_constraints_snapshot_pgsql.php delete mode 100644 tests/comparisons/Migration/sqlite/test_composite_constraints_snapshot_sqlite.php delete mode 100644 tests/comparisons/Migration/test_composite_constraints_snapshot.php diff --git a/tests/TestCase/MigrationsTest.php b/tests/TestCase/MigrationsTest.php index e014c139..60defff0 100644 --- a/tests/TestCase/MigrationsTest.php +++ b/tests/TestCase/MigrationsTest.php @@ -468,7 +468,6 @@ public function migrationsProvider() [ Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS, [ - ['test_composite_constraints_snapshot', 20150912015600], ['test_not_empty_snapshot', 20150912015601], ['test_auto_id_disabled_snapshot', 20150912015602], ['testCreatePrimaryKey', 20150912015603], @@ -478,7 +477,6 @@ public function migrationsProvider() [ Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS . 'pgsql' . DS, [ - ['test_composite_constraints_snapshot_pgsql', 20150912015605], ['test_not_empty_snapshot_pgsql', 20150912015606], ['test_auto_id_disabled_snapshot_pgsql', 20150912015607] ] @@ -487,7 +485,6 @@ public function migrationsProvider() [ Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS . 'sqlite' . DS, [ - ['test_composite_constraints_snapshot_sqlite', 20150912015608], ['test_not_empty_snapshot_sqlite', 20150912015609], ['test_auto_id_disabled_snapshot_sqlite', 20150912015610] ] diff --git a/tests/TestCase/Shell/Task/MigrationSnapshotTaskTest.php b/tests/TestCase/Shell/Task/MigrationSnapshotTaskTest.php index b65c5d0d..ce177f70 100644 --- a/tests/TestCase/Shell/Task/MigrationSnapshotTaskTest.php +++ b/tests/TestCase/Shell/Task/MigrationSnapshotTaskTest.php @@ -36,8 +36,6 @@ class MigrationSnapshotTaskTest extends TestCase 'plugin.migrations.articles' ]; - public $autoFixtures = false; - /** * setup method * @@ -63,16 +61,6 @@ public function setUp() public function testNotEmptySnapshot() { - $this->loadFixtures( - 'Users', - 'SpecialTags', - 'SpecialPk', - 'CompositePk', - 'Categories', - 'Products', - 'Articles' - ); - $this->Task->params['require-table'] = false; $this->Task->params['connection'] = 'test'; $this->Task->params['plugin'] = 'BogusPlugin'; @@ -105,21 +93,6 @@ public function testAutoIdDisabledSnapshot() $this->assertCorrectSnapshot($bakeName, $result); } - public function testCompositeConstraintsSnapshot() - { - $this->loadFixtures( - 'Orders' - ); - - $this->Task->params['require-table'] = false; - $this->Task->params['connection'] = 'test'; - - $bakeName = $this->getBakeName('TestCompositeConstraintsSnapshot'); - $result = $this->Task->bake($bakeName); - - $this->assertCorrectSnapshot($bakeName, $result); - } - public function getBakeName($name) { $dbenv = getenv("DB"); diff --git a/tests/comparisons/Migration/pgsql/test_auto_id_disabled_snapshot_pgsql.php b/tests/comparisons/Migration/pgsql/test_auto_id_disabled_snapshot_pgsql.php index a47a5803..af2e96e8 100644 --- a/tests/comparisons/Migration/pgsql/test_auto_id_disabled_snapshot_pgsql.php +++ b/tests/comparisons/Migration/pgsql/test_auto_id_disabled_snapshot_pgsql.php @@ -112,6 +112,33 @@ public function up() ->addPrimaryKey(['id', 'name']) ->create(); + $table = $this->table('orders'); + $table + ->addColumn('id', 'integer', [ + 'autoIncrement' => true, + 'default' => null, + 'limit' => 10, + 'null' => false, + ]) + ->addPrimaryKey(['id']) + ->addColumn('product_category', 'integer', [ + 'default' => null, + 'limit' => 10, + 'null' => false, + ]) + ->addColumn('product_id', 'integer', [ + 'default' => null, + 'limit' => 10, + 'null' => false, + ]) + ->addIndex( + [ + 'product_category', + 'product_id', + ] + ) + ->create(); + $table = $this->table('products'); $table ->addColumn('id', 'integer', [ @@ -275,6 +302,24 @@ public function up() ) ->update(); + $this->table('orders') + ->addForeignKey( + [ + 'product_category', + 'product_id', + ], + 'products', + [ + 'category_id', + 'id', + ], + [ + 'update' => 'CASCADE', + 'delete' => 'CASCADE' + ] + ) + ->update(); + $this->table('products') ->addForeignKey( 'category_id', @@ -299,6 +344,14 @@ public function down() 'product_id' ); + $this->table('orders') + ->dropForeignKey( + [ + 'product_category', + 'product_id', + ] + ); + $this->table('products') ->dropForeignKey( 'category_id' @@ -307,6 +360,7 @@ public function down() $this->dropTable('articles'); $this->dropTable('categories'); $this->dropTable('composite_pks'); + $this->dropTable('orders'); $this->dropTable('products'); $this->dropTable('special_pks'); $this->dropTable('special_tags'); diff --git a/tests/comparisons/Migration/pgsql/test_composite_constraints_snapshot_pgsql.php b/tests/comparisons/Migration/pgsql/test_composite_constraints_snapshot_pgsql.php deleted file mode 100644 index eff037b2..00000000 --- a/tests/comparisons/Migration/pgsql/test_composite_constraints_snapshot_pgsql.php +++ /dev/null @@ -1,322 +0,0 @@ -table('articles'); - $table - ->addColumn('title', 'string', [ - 'comment' => 'Article title', - 'default' => 'NULL::character varying', - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('category_id', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => true, - ]) - ->addColumn('product_id', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'category_id', - ] - ) - ->addIndex( - [ - 'product_id', - ] - ) - ->create(); - - $table = $this->table('categories'); - $table - ->addColumn('parent_id', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => true, - ]) - ->addColumn('title', 'string', [ - 'default' => 'NULL::character varying', - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('slug', 'string', [ - 'default' => 'NULL::character varying', - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'slug', - ], - ['unique' => true] - ) - ->create(); - - $table = $this->table('composite_pks', ['id' => false, 'primary_key' => ['id', 'name']]); - $table - ->addColumn('id', 'uuid', [ - 'default' => 'a4950df3-515f-474c-be4c-6a027c1957e7', - 'limit' => null, - 'null' => false, - ]) - ->addColumn('name', 'string', [ - 'default' => '', - 'limit' => 50, - 'null' => false, - ]) - ->create(); - - $table = $this->table('orders'); - $table - ->addColumn('product_category', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => false, - ]) - ->addColumn('product_id', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => false, - ]) - ->addIndex( - [ - 'product_category', - 'product_id', - ] - ) - ->create(); - - $table = $this->table('products'); - $table - ->addColumn('title', 'string', [ - 'default' => 'NULL::character varying', - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('slug', 'string', [ - 'default' => 'NULL::character varying', - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('category_id', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'slug', - ], - ['unique' => true] - ) - ->addIndex( - [ - 'category_id', - 'id', - ], - ['unique' => true] - ) - ->addIndex( - [ - 'category_id', - ] - ) - ->create(); - - $table = $this->table('special_pks', ['id' => false, 'primary_key' => ['id']]); - $table - ->addColumn('id', 'uuid', [ - 'default' => 'a4950df3-515f-474c-be4c-6a027c1957e7', - 'limit' => null, - 'null' => false, - ]) - ->addColumn('name', 'string', [ - 'default' => 'NULL::character varying', - 'limit' => 256, - 'null' => true, - ]) - ->create(); - - $table = $this->table('special_tags'); - $table - ->addColumn('article_id', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => false, - ]) - ->addColumn('author_id', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => true, - ]) - ->addColumn('tag_id', 'integer', [ - 'default' => null, - 'limit' => 10, - 'null' => false, - ]) - ->addColumn('highlighted', 'boolean', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('highlighted_time', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'article_id', - ], - ['unique' => true] - ) - ->create(); - - $table = $this->table('users'); - $table - ->addColumn('username', 'string', [ - 'default' => 'NULL::character varying', - 'limit' => 256, - 'null' => true, - ]) - ->addColumn('password', 'string', [ - 'default' => 'NULL::character varying', - 'limit' => 256, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('updated', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->create(); - - $this->table('articles') - ->addForeignKey( - 'category_id', - 'categories', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->addForeignKey( - 'product_id', - 'products', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - $this->table('orders') - ->addForeignKey( - [ - 'product_category', - 'product_id', - ], - 'products', - [ - 'category_id', - 'id', - ], - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - $this->table('products') - ->addForeignKey( - 'category_id', - 'categories', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - } - - public function down() - { - $this->table('articles') - ->dropForeignKey( - 'category_id' - ) - ->dropForeignKey( - 'product_id' - ); - - $this->table('orders') - ->dropForeignKey( - [ - 'product_category', - 'product_id', - ] - ); - - $this->table('products') - ->dropForeignKey( - 'category_id' - ); - - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); - } -} diff --git a/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php b/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php index b87b29d0..75be90a9 100644 --- a/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php +++ b/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php @@ -94,6 +94,26 @@ public function up() ]) ->create(); + $table = $this->table('orders'); + $table + ->addColumn('product_category', 'integer', [ + 'default' => null, + 'limit' => 10, + 'null' => false, + ]) + ->addColumn('product_id', 'integer', [ + 'default' => null, + 'limit' => 10, + 'null' => false, + ]) + ->addIndex( + [ + 'product_category', + 'product_id', + ] + ) + ->create(); + $table = $this->table('products'); $table ->addColumn('title', 'string', [ @@ -235,6 +255,24 @@ public function up() ) ->update(); + $this->table('orders') + ->addForeignKey( + [ + 'product_category', + 'product_id', + ], + 'products', + [ + 'category_id', + 'id', + ], + [ + 'update' => 'CASCADE', + 'delete' => 'CASCADE' + ] + ) + ->update(); + $this->table('products') ->addForeignKey( 'category_id', @@ -259,6 +297,14 @@ public function down() 'product_id' ); + $this->table('orders') + ->dropForeignKey( + [ + 'product_category', + 'product_id', + ] + ); + $this->table('products') ->dropForeignKey( 'category_id' @@ -267,6 +313,7 @@ public function down() $this->dropTable('articles'); $this->dropTable('categories'); $this->dropTable('composite_pks'); + $this->dropTable('orders'); $this->dropTable('products'); $this->dropTable('special_pks'); $this->dropTable('special_tags'); diff --git a/tests/comparisons/Migration/sqlite/test_auto_id_disabled_snapshot_sqlite.php b/tests/comparisons/Migration/sqlite/test_auto_id_disabled_snapshot_sqlite.php index b8aa5064..aa661153 100644 --- a/tests/comparisons/Migration/sqlite/test_auto_id_disabled_snapshot_sqlite.php +++ b/tests/comparisons/Migration/sqlite/test_auto_id_disabled_snapshot_sqlite.php @@ -111,6 +111,33 @@ public function up() ->addPrimaryKey(['id', 'name']) ->create(); + $table = $this->table('orders'); + $table + ->addColumn('id', 'integer', [ + 'autoIncrement' => true, + 'default' => null, + 'limit' => null, + 'null' => false, + ]) + ->addPrimaryKey(['id']) + ->addColumn('product_category', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addColumn('product_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addIndex( + [ + 'product_category', + 'product_id', + ] + ) + ->create(); + $table = $this->table('products'); $table ->addColumn('id', 'integer', [ @@ -274,6 +301,24 @@ public function up() ) ->update(); + $this->table('orders') + ->addForeignKey( + [ + 'product_category', + 'product_id', + ], + 'products', + [ + 'category_id', + 'id', + ], + [ + 'update' => 'CASCADE', + 'delete' => 'CASCADE' + ] + ) + ->update(); + $this->table('products') ->addForeignKey( 'category_id', @@ -298,6 +343,14 @@ public function down() 'product_id' ); + $this->table('orders') + ->dropForeignKey( + [ + 'product_category', + 'product_id', + ] + ); + $this->table('products') ->dropForeignKey( 'category_id' @@ -306,6 +359,7 @@ public function down() $this->dropTable('articles'); $this->dropTable('categories'); $this->dropTable('composite_pks'); + $this->dropTable('orders'); $this->dropTable('products'); $this->dropTable('special_pks'); $this->dropTable('special_tags'); diff --git a/tests/comparisons/Migration/sqlite/test_composite_constraints_snapshot_sqlite.php b/tests/comparisons/Migration/sqlite/test_composite_constraints_snapshot_sqlite.php deleted file mode 100644 index 9495dc23..00000000 --- a/tests/comparisons/Migration/sqlite/test_composite_constraints_snapshot_sqlite.php +++ /dev/null @@ -1,321 +0,0 @@ -table('articles'); - $table - ->addColumn('title', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('category_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('product_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'category_id', - ] - ) - ->addIndex( - [ - 'product_id', - ] - ) - ->create(); - - $table = $this->table('categories'); - $table - ->addColumn('parent_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('title', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('slug', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'slug', - ], - ['unique' => true] - ) - ->create(); - - $table = $this->table('composite_pks', ['id' => false, 'primary_key' => ['id', 'name']]); - $table - ->addColumn('id', 'uuid', [ - 'default' => 'a4950df3-515f-474c-be4c-6a027c1957e7', - 'limit' => null, - 'null' => false, - ]) - ->addColumn('name', 'string', [ - 'default' => '', - 'limit' => 50, - 'null' => false, - ]) - ->create(); - - $table = $this->table('orders'); - $table - ->addColumn('product_category', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]) - ->addColumn('product_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]) - ->addIndex( - [ - 'product_category', - 'product_id', - ] - ) - ->create(); - - $table = $this->table('products'); - $table - ->addColumn('title', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('slug', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('category_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'slug', - ], - ['unique' => true] - ) - ->addIndex( - [ - 'category_id', - 'id', - ], - ['unique' => true] - ) - ->addIndex( - [ - 'category_id', - ] - ) - ->create(); - - $table = $this->table('special_pks', ['id' => false, 'primary_key' => ['id']]); - $table - ->addColumn('id', 'uuid', [ - 'default' => 'a4950df3-515f-474c-be4c-6a027c1957e7', - 'limit' => null, - 'null' => false, - ]) - ->addColumn('name', 'string', [ - 'default' => null, - 'limit' => 256, - 'null' => true, - ]) - ->create(); - - $table = $this->table('special_tags'); - $table - ->addColumn('article_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]) - ->addColumn('author_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('tag_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]) - ->addColumn('highlighted', 'boolean', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('highlighted_time', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'article_id', - ], - ['unique' => true] - ) - ->create(); - - $table = $this->table('users'); - $table - ->addColumn('username', 'string', [ - 'default' => null, - 'limit' => 256, - 'null' => true, - ]) - ->addColumn('password', 'string', [ - 'default' => null, - 'limit' => 256, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('updated', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->create(); - - $this->table('articles') - ->addForeignKey( - 'category_id', - 'categories', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->addForeignKey( - 'product_id', - 'products', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - $this->table('orders') - ->addForeignKey( - [ - 'product_category', - 'product_id', - ], - 'products', - [ - 'category_id', - 'id', - ], - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - $this->table('products') - ->addForeignKey( - 'category_id', - 'categories', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - } - - public function down() - { - $this->table('articles') - ->dropForeignKey( - 'category_id' - ) - ->dropForeignKey( - 'product_id' - ); - - $this->table('orders') - ->dropForeignKey( - [ - 'product_category', - 'product_id', - ] - ); - - $this->table('products') - ->dropForeignKey( - 'category_id' - ); - - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); - } -} diff --git a/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php b/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php index 36efb162..fc54c8b6 100644 --- a/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php +++ b/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php @@ -93,6 +93,26 @@ public function up() ]) ->create(); + $table = $this->table('orders'); + $table + ->addColumn('product_category', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addColumn('product_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addIndex( + [ + 'product_category', + 'product_id', + ] + ) + ->create(); + $table = $this->table('products'); $table ->addColumn('title', 'string', [ @@ -234,6 +254,24 @@ public function up() ) ->update(); + $this->table('orders') + ->addForeignKey( + [ + 'product_category', + 'product_id', + ], + 'products', + [ + 'category_id', + 'id', + ], + [ + 'update' => 'CASCADE', + 'delete' => 'CASCADE' + ] + ) + ->update(); + $this->table('products') ->addForeignKey( 'category_id', @@ -258,6 +296,14 @@ public function down() 'product_id' ); + $this->table('orders') + ->dropForeignKey( + [ + 'product_category', + 'product_id', + ] + ); + $this->table('products') ->dropForeignKey( 'category_id' @@ -266,6 +312,7 @@ public function down() $this->dropTable('articles'); $this->dropTable('categories'); $this->dropTable('composite_pks'); + $this->dropTable('orders'); $this->dropTable('products'); $this->dropTable('special_pks'); $this->dropTable('special_tags'); diff --git a/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php b/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php index f66d0b1f..cb5ffb05 100644 --- a/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php +++ b/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php @@ -112,6 +112,33 @@ public function up() ->addPrimaryKey(['id', 'name']) ->create(); + $table = $this->table('orders'); + $table + ->addColumn('id', 'integer', [ + 'autoIncrement' => true, + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addPrimaryKey(['id']) + ->addColumn('product_category', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addColumn('product_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addIndex( + [ + 'product_category', + 'product_id', + ] + ) + ->create(); + $table = $this->table('products'); $table ->addColumn('id', 'integer', [ @@ -275,6 +302,24 @@ public function up() ) ->update(); + $this->table('orders') + ->addForeignKey( + [ + 'product_category', + 'product_id', + ], + 'products', + [ + 'category_id', + 'id', + ], + [ + 'update' => 'CASCADE', + 'delete' => 'CASCADE' + ] + ) + ->update(); + $this->table('products') ->addForeignKey( 'category_id', @@ -299,6 +344,14 @@ public function down() 'product_id' ); + $this->table('orders') + ->dropForeignKey( + [ + 'product_category', + 'product_id', + ] + ); + $this->table('products') ->dropForeignKey( 'category_id' @@ -307,6 +360,7 @@ public function down() $this->dropTable('articles'); $this->dropTable('categories'); $this->dropTable('composite_pks'); + $this->dropTable('orders'); $this->dropTable('products'); $this->dropTable('special_pks'); $this->dropTable('special_tags'); diff --git a/tests/comparisons/Migration/test_composite_constraints_snapshot.php b/tests/comparisons/Migration/test_composite_constraints_snapshot.php deleted file mode 100644 index 2e2dd1e4..00000000 --- a/tests/comparisons/Migration/test_composite_constraints_snapshot.php +++ /dev/null @@ -1,322 +0,0 @@ -table('articles'); - $table - ->addColumn('title', 'string', [ - 'comment' => 'Article title', - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('category_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('product_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'category_id', - ] - ) - ->addIndex( - [ - 'product_id', - ] - ) - ->create(); - - $table = $this->table('categories'); - $table - ->addColumn('parent_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('title', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('slug', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'slug', - ], - ['unique' => true] - ) - ->create(); - - $table = $this->table('composite_pks', ['id' => false, 'primary_key' => ['id', 'name']]); - $table - ->addColumn('id', 'uuid', [ - 'default' => 'a4950df3-515f-474c-be4c-6a027c1957e7', - 'limit' => null, - 'null' => false, - ]) - ->addColumn('name', 'string', [ - 'default' => '', - 'limit' => 50, - 'null' => false, - ]) - ->create(); - - $table = $this->table('orders'); - $table - ->addColumn('product_category', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]) - ->addColumn('product_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]) - ->addIndex( - [ - 'product_category', - 'product_id', - ] - ) - ->create(); - - $table = $this->table('products'); - $table - ->addColumn('title', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('slug', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]) - ->addColumn('category_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('modified', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'slug', - ], - ['unique' => true] - ) - ->addIndex( - [ - 'category_id', - 'id', - ], - ['unique' => true] - ) - ->addIndex( - [ - 'category_id', - ] - ) - ->create(); - - $table = $this->table('special_pks', ['id' => false, 'primary_key' => ['id']]); - $table - ->addColumn('id', 'uuid', [ - 'default' => 'a4950df3-515f-474c-be4c-6a027c1957e7', - 'limit' => null, - 'null' => false, - ]) - ->addColumn('name', 'string', [ - 'default' => null, - 'limit' => 256, - 'null' => true, - ]) - ->create(); - - $table = $this->table('special_tags'); - $table - ->addColumn('article_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]) - ->addColumn('author_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]) - ->addColumn('tag_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]) - ->addColumn('highlighted', 'boolean', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('highlighted_time', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addIndex( - [ - 'article_id', - ], - ['unique' => true] - ) - ->create(); - - $table = $this->table('users'); - $table - ->addColumn('username', 'string', [ - 'default' => null, - 'limit' => 256, - 'null' => true, - ]) - ->addColumn('password', 'string', [ - 'default' => null, - 'limit' => 256, - 'null' => true, - ]) - ->addColumn('created', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->addColumn('updated', 'timestamp', [ - 'default' => null, - 'limit' => null, - 'null' => true, - ]) - ->create(); - - $this->table('articles') - ->addForeignKey( - 'category_id', - 'categories', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->addForeignKey( - 'product_id', - 'products', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - $this->table('orders') - ->addForeignKey( - [ - 'product_category', - 'product_id', - ], - 'products', - [ - 'category_id', - 'id', - ], - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - $this->table('products') - ->addForeignKey( - 'category_id', - 'categories', - 'id', - [ - 'update' => 'CASCADE', - 'delete' => 'CASCADE' - ] - ) - ->update(); - - } - - public function down() - { - $this->table('articles') - ->dropForeignKey( - 'category_id' - ) - ->dropForeignKey( - 'product_id' - ); - - $this->table('orders') - ->dropForeignKey( - [ - 'product_category', - 'product_id', - ] - ); - - $this->table('products') - ->dropForeignKey( - 'category_id' - ); - - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); - } -} diff --git a/tests/comparisons/Migration/test_not_empty_snapshot.php b/tests/comparisons/Migration/test_not_empty_snapshot.php index ad5eceb4..6cfbbe56 100644 --- a/tests/comparisons/Migration/test_not_empty_snapshot.php +++ b/tests/comparisons/Migration/test_not_empty_snapshot.php @@ -94,6 +94,26 @@ public function up() ]) ->create(); + $table = $this->table('orders'); + $table + ->addColumn('product_category', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addColumn('product_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]) + ->addIndex( + [ + 'product_category', + 'product_id', + ] + ) + ->create(); + $table = $this->table('products'); $table ->addColumn('title', 'string', [ @@ -235,6 +255,24 @@ public function up() ) ->update(); + $this->table('orders') + ->addForeignKey( + [ + 'product_category', + 'product_id', + ], + 'products', + [ + 'category_id', + 'id', + ], + [ + 'update' => 'CASCADE', + 'delete' => 'CASCADE' + ] + ) + ->update(); + $this->table('products') ->addForeignKey( 'category_id', @@ -259,6 +297,14 @@ public function down() 'product_id' ); + $this->table('orders') + ->dropForeignKey( + [ + 'product_category', + 'product_id', + ] + ); + $this->table('products') ->dropForeignKey( 'category_id' @@ -267,6 +313,7 @@ public function down() $this->dropTable('articles'); $this->dropTable('categories'); $this->dropTable('composite_pks'); + $this->dropTable('orders'); $this->dropTable('products'); $this->dropTable('special_pks'); $this->dropTable('special_tags');