Skip to content

Commit

Permalink
Merge pull request #615 from thonhaus/patch-constraintnames
Browse files Browse the repository at this point in the history
Patch constraintnames
  • Loading branch information
markstory authored May 4, 2023
2 parents 0a1e0fe + 2f1388c commit f30c575
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion templates/bake/element/add-foreign-keys.twig
Original file line number Diff line number Diff line change
@@ -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 %}
Expand Down Expand Up @@ -29,6 +29,7 @@
[
'update' => '{{ Migration.formatConstraintAction(constraint['update']) | raw }}',
'delete' => '{{ Migration.formatConstraintAction(constraint['delete']) | raw }}',
'constraint' => '{{ constraintName }}'
]
)
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions templates/bake/element/create-tables.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_article_idx'
]
)
->update();
Expand All @@ -403,6 +404,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'product_id_fk'
]
)
->update();
Expand All @@ -415,6 +417,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'category_idx'
]
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_article_idx'
]
)
->update();
Expand All @@ -343,6 +344,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'product_id_fk'
]
)
->update();
Expand All @@ -355,6 +357,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'category_idx'
]
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_article_idx'
]
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_id_fk'
]
)
->update();
Expand All @@ -386,6 +387,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'product_category_fk'
]
)
->update();
Expand All @@ -398,6 +400,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'category_id_fk'
]
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_id_fk'
]
)
->update();
Expand All @@ -326,6 +327,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'product_category_fk'
]
)
->update();
Expand All @@ -338,6 +340,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'category_id_fk'
]
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_id_fk'
]
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_article_idx'
]
)
->update();
Expand All @@ -387,6 +388,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'product_id_fk'
]
)
->update();
Expand All @@ -399,6 +401,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'category_idx'
]
)
->update();
Expand Down
3 changes: 3 additions & 0 deletions tests/comparisons/Migration/test_not_empty_snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_article_idx'
]
)
->update();
Expand All @@ -327,6 +328,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'product_id_fk'
]
)
->update();
Expand All @@ -339,6 +341,7 @@ public function up(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'category_idx'
]
)
->update();
Expand Down
1 change: 1 addition & 0 deletions tests/comparisons/Migration/test_plugin_blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'category_article_idx'
]
)
->update();
Expand Down

0 comments on commit f30c575

Please sign in to comment.