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

Bugfix: Fix migration crash when using MSSQL as mage database #4695

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

tuokor
Copy link
Contributor

@tuokor tuokor commented Mar 1, 2024

Description

This is a fix for issue #4681 where migration file 90d978a8aef8_update_unique_constraint_for_secret.py crashed due to alembic not supporting constraint retrieval for MSSQL as constraint are implemented as indexes that need to fetched using get_indexes() and dropped via alter table sql command.

How Has This Been Tested?

I verified the changes by setting mage.ai to use sql server as the database and also tested with postgres to make sure changes didn't cause side effects to existing migration code.

  • Migration works with ms sql server
  • Migration still works with postgres

Checklist

  • The PR is tagged with proper labels (bug, enhancement, feature, documentation)
  • I have performed a self-review of my own code
  • I have added unit tests that prove my fix is effective or that my feature works
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • If new documentation has been added, relative paths have been added to the appropriate section of docs/mint.json

cc:
@dy46

…nstraint drop correctly with mssql by using alter command.
@dy46 dy46 added enhancement Polish or UX improvements bug Something isn't working and removed enhancement Polish or UX improvements labels Mar 1, 2024
unique_constraints = insp.get_unique_constraints('secret')
for constraint in unique_constraints:
batch_op.drop_constraint(constraint['name'], type_='unique')
insp = sa.inspect(bind)
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing this line affects the insp in the else block as well.

Copy link
Contributor Author

@tuokor tuokor Mar 4, 2024

Choose a reason for hiding this comment

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

Yes, but it did not affect the results when I tested with different sql servers.

MSSQL server inspection did not work if I had the original line sa.inspect(bind.engine). All inspections calls freeze the migration if bind.engine is used with MSSQL server. I read the documentation the inspect method does accept either an engine or a connection which the bind variable is https://docs.sqlalchemy.org/en/20/core/inspection.html#available-inspection-targets .

Copy link
Contributor Author

@tuokor tuokor Mar 4, 2024

Choose a reason for hiding this comment

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

Here is also documentation about the get_bind() function that states that it returns a Connection object when "online" mode https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.get_bind

@dy46 dy46 merged commit d7759be into mage-ai:master Mar 7, 2024
4 checks passed
@wangxiaoyou1993 wangxiaoyou1993 mentioned this pull request Mar 13, 2024
15 tasks
oonyoontong pushed a commit to bunker-tech/mage-ai that referenced this pull request May 2, 2024
…nstraint drop correctly with mssql by using alter command. (mage-ai#4695)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants