diff --git a/templates/bake/element/add-foreign-keys.twig b/templates/bake/element/add-foreign-keys.twig index ef75c63a..6df6a12d 100644 --- a/templates/bake/element/add-foreign-keys.twig +++ b/templates/bake/element/add-foreign-keys.twig @@ -1,6 +1,6 @@ {% set statement = Migration.tableStatement(table, true) %} {% set hasProcessedConstraint = false %} -{% for constraint in constraints %} +{% for constraintName, constraint in constraints[table] %} {% set constraintColumns = constraint['columns']|sort %} {% if constraint['type'] != 'unique' %} {% set hasProcessedConstraint = true %} @@ -29,6 +29,7 @@ [ 'update' => '{{ Migration.formatConstraintAction(constraint['update']) | raw }}', 'delete' => '{{ Migration.formatConstraintAction(constraint['delete']) | raw }}', + 'constraint' => '{{ constraintName }}' ] ) {% endif %} diff --git a/templates/bake/element/create-tables.twig b/templates/bake/element/create-tables.twig index 8f4a2e33..32f776a3 100644 --- a/templates/bake/element/create-tables.twig +++ b/templates/bake/element/create-tables.twig @@ -62,8 +62,8 @@ {% if createData.constraints %} {% for table, tableConstraints in createData.constraints %} {{- element('Migrations.add-foreign-keys', { - constraints: tableConstraints, - table: table + constraints: createData.constraints, + table: table, }) -}} {% endfor -%} 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 64b2fe24..05d20737 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 @@ -385,6 +385,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_article_idx' ] ) ->update(); @@ -403,6 +404,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'product_id_fk' ] ) ->update(); @@ -415,6 +417,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'category_idx' ] ) ->update(); 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 42eff43e..b5e768ee 100644 --- a/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php +++ b/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php @@ -325,6 +325,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_article_idx' ] ) ->update(); @@ -343,6 +344,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'product_id_fk' ] ) ->update(); @@ -355,6 +357,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'category_idx' ] ) ->update(); diff --git a/tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php b/tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php index df2268eb..b2270c1f 100644 --- a/tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php +++ b/tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php @@ -131,6 +131,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_article_idx' ] ) ->update(); 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 2ee341b8..931b5abe 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 @@ -368,6 +368,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_id_fk' ] ) ->update(); @@ -386,6 +387,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'product_category_fk' ] ) ->update(); @@ -398,6 +400,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'category_id_fk' ] ) ->update(); 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 6271b198..2da794ab 100644 --- a/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php +++ b/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php @@ -308,6 +308,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_id_fk' ] ) ->update(); @@ -326,6 +327,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'product_category_fk' ] ) ->update(); @@ -338,6 +340,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'category_id_fk' ] ) ->update(); diff --git a/tests/comparisons/Migration/sqlite/test_plugin_blog_sqlite.php b/tests/comparisons/Migration/sqlite/test_plugin_blog_sqlite.php index 190bfa0b..4e1a8d6f 100644 --- a/tests/comparisons/Migration/sqlite/test_plugin_blog_sqlite.php +++ b/tests/comparisons/Migration/sqlite/test_plugin_blog_sqlite.php @@ -124,6 +124,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_id_fk' ] ) ->update(); diff --git a/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php b/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php index 9a98d154..7a58b42a 100644 --- a/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php +++ b/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php @@ -369,6 +369,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_article_idx' ] ) ->update(); @@ -387,6 +388,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'product_id_fk' ] ) ->update(); @@ -399,6 +401,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'category_idx' ] ) ->update(); diff --git a/tests/comparisons/Migration/test_not_empty_snapshot.php b/tests/comparisons/Migration/test_not_empty_snapshot.php index 9490a5d7..862b2dfe 100644 --- a/tests/comparisons/Migration/test_not_empty_snapshot.php +++ b/tests/comparisons/Migration/test_not_empty_snapshot.php @@ -309,6 +309,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_article_idx' ] ) ->update(); @@ -327,6 +328,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'product_id_fk' ] ) ->update(); @@ -339,6 +341,7 @@ public function up(): void [ 'update' => 'CASCADE', 'delete' => 'CASCADE', + 'constraint' => 'category_idx' ] ) ->update(); diff --git a/tests/comparisons/Migration/test_plugin_blog.php b/tests/comparisons/Migration/test_plugin_blog.php index 0120e7bb..4dea5ce6 100644 --- a/tests/comparisons/Migration/test_plugin_blog.php +++ b/tests/comparisons/Migration/test_plugin_blog.php @@ -125,6 +125,7 @@ public function up(): void [ 'update' => 'NO_ACTION', 'delete' => 'NO_ACTION', + 'constraint' => 'category_article_idx' ] ) ->update();