Skip to content

Pass direction to SQL::Translator::Diff#81

Open
KES777 wants to merge 1 commit intofrioux:mainfrom
KES777:pass_migration_direction_to_sqlt
Open

Pass direction to SQL::Translator::Diff#81
KES777 wants to merge 1 commit intofrioux:mainfrom
KES777:pass_migration_direction_to_sqlt

Conversation

@KES777
Copy link

@KES777 KES777 commented Apr 3, 2025

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 upgrade migration v1->v2 it was renamed and now during downgrade v2->v1 we expect it should be renamed back. But instead the 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.

Proposition

From the above to get the expected result during downgrades we need to pass the flag that the downgrade migration should be generated.

 ### 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant