Skip to content
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

Render if_not_exists option for CreateTableOp, CreateIndexOp, DropTableOp and DropIndexOp #1446

Closed
wants to merge 2 commits into from

Conversation

lachaib
Copy link
Contributor

@lachaib lachaib commented Mar 19, 2024

Related: #151

Description

Without opinion on whether or not the option if_not_exists or if_exists should be set by default (or configurable via AutogenContext), I think a follow-up on
#151 should be that if_not_exists or if_exists attributes should be that they are rendered during autogen steps.

How I intend to use it: specify the attribute during rewrites of the pipeline

@writer.rewrites(ops.CreateIndexOp)
def create_index_if_not_exist(_autogen_context, _revision, op: ops.CreateIndexOp):
    op.if_not_exists = True
    return op


@writer.rewrites(ops.DropIndexOp)
def drop_index_if_exist(_autogen_context, _revision, op: ops.DropIndexOp):
    op.if_exists = True
    return op

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

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

sorry I kinda lost this PR.

configurable via AutogenContext

It may make sense. @zzzeek what do you think about adding an option to control this?

It's missing a changelog. see example in https://github.com/sqlalchemy/alembic/tree/main/docs/build/unreleased

Feel free to add something like "pull request courtesy of "

@lachaib
Copy link
Contributor Author

lachaib commented Aug 28, 2024

Hi @CaselIT, thanks for the review. I rebased upon main branch & added a changelog entry. Feel free to tell me how in any way I can now help this pull request move forward.

@CaselIT
Copy link
Member

CaselIT commented Aug 28, 2024

Let's wait on mike's opinion on the flag(s) in autogenerate

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 7ddeaab of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change 7ddeaab: https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5454

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

Hi, this is sqla-tester and I see you've pinged me for review. However, user lachaib is not authorized to initiate CI jobs. Please wait for a project member to do this!

@lachaib lachaib requested a review from CaselIT August 28, 2024 07:44
@zzzeek
Copy link
Member

zzzeek commented Aug 28, 2024

hi!

sorry didnt see this.

Turns out we are also getting ready to merge the same option for tables in #1521.

So I want to get #1521 merged and then we can update this to support autogen for both index and table, hows that?

I understand this got ignored for 6 months so if you aren't around I'll just pull this in and finish it up.

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision cb57978 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset cb57978 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5454

@lachaib
Copy link
Contributor Author

lachaib commented Aug 28, 2024

Ok ping me when the other PR is merged and I'll take care.

@sqla-tester
Copy link
Collaborator

Michael Bayer (zzzeek) wrote:

OK this is ready for adding if_exists / if_not_exists rendering support for create_table and drop_table also

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5454

@lachaib
Copy link
Contributor Author

lachaib commented Sep 13, 2024

I've seen the PR merged, gonna take care of this over the weekend

@CaselIT
Copy link
Member

CaselIT commented Sep 13, 2024

Thanks!

@lachaib
Copy link
Contributor Author

lachaib commented Sep 13, 2024

@zzzeek @CaselIT I proudly present the updated PR with render as well on tables 😁

@lachaib lachaib changed the title Render if_not_exists option for CreateIndexOp and DropIndexOp Render if_not_exists option for CreateTableOp, CreateIndexOp, DropTableOp and DropIndexOp Sep 16, 2024
@lachaib
Copy link
Contributor Author

lachaib commented Sep 23, 2024

@zzzeek @CaselIT , any chance this PR may get merged soon? I have incoming works regarding our migrations and I'd be delighted to include a new alembic along the way

@zzzeek
Copy link
Member

zzzeek commented Sep 23, 2024

sorry I get no notification that anything changed here, will run it through now

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 90c9735 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset 90c9735 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5454

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5454 has been merged. Congratulations! :)

@zzzeek
Copy link
Member

zzzeek commented Sep 23, 2024

alembic 1.13.3 is released now with this change

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.

4 participants