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

fix: remove old constraint #29649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

betodealmeida
Copy link
Member

SUMMARY

The dataset model has a comment that says:

# Note this uniqueness constraint is not part of the physical schema, i.e., it does
# not exist in the migrations, but is required by `import_from_dict` to ensure the
# correct filters are applied in order to identify uniqueness.
#
# The reason it does not physically exist is MySQL, PostgreSQL, etc. have a
# different interpretation of uniqueness when it comes to NULL which is problematic
# given the schema is optional.
__table_args__ = (
UniqueConstraint("database_id", "catalog", "schema", "table_name"),
)

But turns out there is an old migration from 2016 that adds the uniqueness constraint to the schema:

op.create_unique_constraint(
"_customer_location_uc", "tables", ["database_id", "schema", "table_name"]
)

With the introduction of catalogs in SIP-95 this constraint needs to either be updated to include catalog, or removed to align with the SqlaTable model. In this PR I went with the latter.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@betodealmeida betodealmeida requested a review from a team as a code owner July 19, 2024 20:19
@github-actions github-actions bot added the risk:db-migration PRs that require a DB migration label Jul 19, 2024
@dosubot dosubot bot added the change:backend Requires changing the backend label Jul 19, 2024
drop_unique_constraint(op, "_customer_location_uc", "tables")
except Exception: # pylint: disable=broad-except
# Unfortunately the DB migration that creates this constraint has a
# try/except block, so that we can't know for sure if the constraint exists.
Copy link
Member

Choose a reason for hiding this comment

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

Should we raise again if it fails so that it rolls back? What are the implications here if there is an error and we can't roll back the transaction because we are not raising again? Can you use generic_find_uq_constraint_name to see if the constraint exists?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good point, I think we can use generic_find_constraint_name. I'm a bit concerned that the method might not work for all databases, but it should work with the most common at least.

@mistercrunch
Copy link
Member

Hey, thinking about applying some of the ideas in #29546, which would point towards either accumulating this PR and holding it until next release, or merging this in to a no-op place that we would bring into an actual migration later.

Curious as to whether you all think it's better to hold the PR, or to merge into a temporary place.

@mistercrunch
Copy link
Member

Easiest option here seems like it'd be to add a hold:next-major:migration label (or similar) and defer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:backend Requires changing the backend hold:next-major:migration risk:db-migration PRs that require a DB migration size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants