Skip to content

Commit b218b54

Browse files
author
Eugen Konkov
committed
Pass direction to SQL::Translator::Diff
### Why direction of migration is required Imagine this steps: V1 | V2 | V3 --- | --- | --- X | Y:RX | X Where `X` is column name, `Y:RX` is column with `Y` name and `reanmed_from` property set to `X` name. ### What happens when we generate migration scripts Migration | Diff result `[src, tar]` | Description --- | --- | --- v1 -> v2 | X, Y:RX | This works well. The `X` was renamed to `Y`. v2 -> v3 | Y:RX, X | This is also expected. The `Y` was dropped and `X` was created. v2 -> v1 | Y:RX, X | For downgrade script it is not expected that `Y` will be dropped and `X` will be created from scratch. During migration `v1->v2` it was renamed and now durint `v2->v1` we expect it should be renamed back. But this drop happens because it works as designed for `upgrade` direction. But this scenario it is `downgrade`. Unfortunately We can not detect this automatically: the order of `[src, dst]` is the same and the set of `extra` properties are the same. (For now I am skipping more complex scenarios when `v3` migration has columns with created and/or renamed names similar to `v2` version and its consequences on `v1`) ### Proposition From the above to get the expected result during `downgrades` we need to pass the direction that the `downgrade` migration should be generated.
1 parent b246341 commit b218b54

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ sub _sqldiff_from_yaml {
533533
my @stmts = SQL::Translator::Diff::schema_diff(
534534
$source_schema, $db,
535535
$dest_schema, $db,
536-
{ sqlt_args => $sqltargs }
536+
{ sqlt_args => { direction => $direction, %$sqltargs } },
537537
);
538538

539539
if (!$self->txn_prep && $self->txn_wrap) {

0 commit comments

Comments
 (0)