Skip to content

Conversation

KES777
Copy link
Contributor

@KES777 KES777 commented Apr 5, 2025

In this PR we:

  • Add more tests for renames workflows.
  • Simplify code to detect renames.
    Now function could be easily reused for different types of objects
  • Document code
  • Fix the issue when field is created before renames happened.
    This happens when we want to drop the old object and give the name of dropped object to another one.

This changes are related to #184

Eugen Konkov added 3 commits April 3, 2025 22:44
When object has 'renamed_from' property, but the previous version does not exists, the
warning should be issued and for this object CREATE XXX query should be generated.
Fixes: 185

GitHub: dbsrgits#185
@KES777 KES777 force-pushed the implement_tests_for_renames branch from 0575de1 to 9ddf601 Compare April 5, 2025 03:16
@KES777
Copy link
Contributor Author

KES777 commented Apr 6, 2025

Also fixes this: jjn1056/DBIx-Class-Migration#129

Eugen Konkov added 5 commits May 4, 2025 17:03
Renames should go first, otherwise it could not be possible to add a new column with
the name which was just renamed to something. Eg. SRC:x->DST:y, Create DST:x.
Otherwise we can not run 'Create DST:x', because schema still have 'x' column.
@KES777 KES777 force-pushed the implement_tests_for_renames branch from f9e50ba to fd58e13 Compare May 4, 2025 21:03
Copy link
Contributor

@rabbiveesh rabbiveesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies on the slow turnaround; out of perl now and just started a new $job, but i'll see if i can squeeze this in.
Trying to understand the full intent + then i can dig into more

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests here have nothing to do with the rest of the producer behaviors, could you just put this in a new diff test which produces yaml?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw it was done few month ago.

# alter ( $src_version, $dst_version )
# create( $dst_version )
# drop ( $src_version )
# next ( $dst_name, $dst_version )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not understanding what the next callback is meant to do; would you mind expounding on that?

Copy link
Contributor Author

@KES777 KES777 Jun 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next call back is fired for every dst column. This is to run some code for each dst name/column/table.

At the moment this call back is used to prepare/initialize required data structures which will be filled/used later.
image

I agree that the name is not the best. Probably it could be better if we name it every or init. Just suggest better name you like and I'll change it.

@KES777
Copy link
Contributor Author

KES777 commented Jun 8, 2025

Intention in this PR is to fix bugs, generalize code and extend tests.

@KES777 KES777 requested a review from rabbiveesh June 8, 2025 19:07
# now add everything else
push @sql, batch_alter_table_statements(
$diff_hash, $options, qw(
rename_field

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that this change corresponds to the change at https://github.com/dbsrgits/sql-translator/pull/188/files#diff-d1a0629b4bf9c95c1131cc9eaadd08c23943af65ad4b679de4b8190ee019a87bR315-R317, but I don't see why there needs to be a reorder of these entries.

Copy link
Contributor Author

@KES777 KES777 Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewpersico Thank you for doing review.

It is documented in the commit: 740fa22

Renames should go first, otherwise it could not be possible to add a new column with the name which was just renamed to something. Eg. SRC:x->DST:y, Create DST:x.
Otherwise we can not run 'Create DST:x', because schema still have 'x' column.

Compare:
SRC:x->DST:y, Create DST:x. This works because x was renamed, then we can create field x.
VS
Create DST:x, SRC:x->DST:y. This does not work. We can not create x because schema already has x. Though it will be renamed a few seconds later.

Almost the same logic as for the case when we should drop before add.

Copy link
Contributor Author

@KES777 KES777 Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated statements should be in the same order. Imagine if here
image

a column is not renamed to something else (1), then ADD COLUMN statement (2) will fail.

@KES777 KES777 requested a review from matthewpersico October 7, 2025 00:11
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.

3 participants