-
Notifications
You must be signed in to change notification settings - Fork 90
Do not drop renamed field at 'downgrade' migration script #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Can i bother you to add a test for this? otherwise i'll write one myself, but it won't be right away. |
Yes, I would like to write, but I do not see a proper way how to do that. I need more insights on this, eg. how to setup I do not want it to stale for a while again. Please provide more thoughts, if you are Ok we can even arrange a call. |
well, since it's just logic, you can set up a test where you provide 2 incredibly minimal yaml schema, and then test that the conversion is generated sensibly in both directions; |
you can always shoot me a message on irc, i'm veesh on perl + libera |
Ah! I got it! I was thinking about SQL schema, but yaml will resolve the problem. Thanks for the hint!!! 🚀 |
hm... this discovers another bug: renamed tables are dropped/added during downgrades =( |
From having peeked at the original code, it should be the same fix just
about
…On Mon, Mar 31, 2025, 03:58 Eugen Konkov ***@***.***> wrote:
hm... this discovers another bug: renamed tables are dropped/added during
downgrades =(
I suppose the algorithm should be improved.
—
Reply to this email directly, view it on GitHub
<#184 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFURPKVVCL5ER35H5IYNYDL2XCHM7AVCNFSM6AAAAABZ3YJJTWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRUHA3DCMZTHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
[image: KES777]*KES777* left a comment (dbsrgits/sql-translator#184)
<#184 (comment)>
hm... this discovers another bug: renamed tables are dropped/added during
downgrades =(
I suppose the algorithm should be improved.
—
Reply to this email directly, view it on GitHub
<#184 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFURPKVVCL5ER35H5IYNYDL2XCHM7AVCNFSM6AAAAABZ3YJJTWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRUHA3DCMZTHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I did deeper analysis. It could not be fixed easily. We need to pass additionally the direction of migration: downgrade or upgrade. This is the bigger change and need to be negotiated. Why direction of migration is requiredImagine this steps:
Where What happens when we generate migration scripts
(For now I am skipping more complex scenarios when PropositionFrom the above to get the expected result during |
Sqlt doesn't have any notion of 'direction', so I dont think that's a
sensible solution.
We can just mark for users that they should be careful about what flags
they use; in the real world you'll have already made a downgrade from 2 to
1 before you changed the setting; I don't view the flag here as a core part
of the schema, it's an added bit for the purpose of diffing
…On Mon, Mar 31, 2025, 21:20 Eugen Konkov ***@***.***> wrote:
I did deeper analysis. It could not be fixed easily. We need to pass
additionally the direction of migration: downgrade or upgrade.
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 name 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. Previously it was renamed and
here we expect it should be renamed back. This happens because it works as
designed for upgraded direction. But this is downgrade, but 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 flag that the downgrade migration should be generated.
—
Reply to this email directly, view it on GitHub
<#184 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFURPKTYB6PT55HUH2MKSID2XGBQFAVCNFSM6AAAAABZ3YJJTWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRXGA2DMMBTGQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
[image: KES777]*KES777* left a comment (dbsrgits/sql-translator#184)
<#184 (comment)>
I did deeper analysis. It could not be fixed easily. We need to pass
additionally the direction of migration: downgrade or upgrade.
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 name 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. Previously it was renamed and
here we expect it should be renamed back. This happens because it works as
designed for upgraded direction. But this is downgrade, but 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 flag that the downgrade migration should be generated.
—
Reply to this email directly, view it on GitHub
<#184 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFURPKTYB6PT55HUH2MKSID2XGBQFAVCNFSM6AAAAABZ3YJJTWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRXGA2DMMBTGQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Ok |
I asked to pass |
I already said that i don't think that 'direction' is in the scope of this tool. |
What do you mean? |
Ignore these changes for a moment. Please let's proceed with #188 first. |
Fixes: #183
This PR fixes the issue with 'downgrade' migration where fields are dropped instead of renamed back.
To show the problem better lets describe migration:
DB version 1 is generated with field name 'comment'
At DB version 2 field 'comment' is renamed to 'new_comment'
'new_comment' field has 'extra'->'renamed_from' property.
Version 1 is the OLD version and has 'comment' (this is source)
Version 2 is the NEW version and has 'new_comment:renamed_from' (this is target)
When upgrade occurs code checks NEW version and sees 'renamed_from' property thus generates 'RENAME COLUMN' DDL.
But for 'downgrade' migration Version 1 and Version 2 have changed places:
Here the old code does not see 'renamed_from' at target, thus generates DROP/ADD DDLs for 'comment/new_comment' fields.
This process looks like this:
Solution
To detect renames for downgrades we need to check additionally SRC field for 'renamed_from' property.
Details
For upgrade, the script works well and generates this diff:
But for downgrade I see this:
The issue is that the previous version does not have
extra->renamed_from
part :DWhen we are upgrading we can see at
Translator::Diff::diff_table_fields
target field is:But when downgrading target field is: