-
Notifications
You must be signed in to change notification settings - Fork 4k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: cascade experiment id fk deletion in datasets table #11966
Open
chilir
wants to merge
3
commits into
mlflow:master
Choose a base branch
from
chilir:cascade-dataset-deletion-2
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
mlflow/store/db_migrations/versions/949ead8d4f49_add_cascading_delete_on_experiments_fk_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""add cascading delete on experiments fk in datasets table | ||
|
||
Revision ID: 949ead8d4f49 | ||
Revises: 867495a8f9d4 | ||
Create Date: 2024-05-09 17:43:49.128493 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "949ead8d4f49" | ||
down_revision = "867495a8f9d4" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
dialect_name = op.get_context().dialect.name | ||
if dialect_name == "sqlite": | ||
# Only way to drop unnamed fk constraint in sqllite | ||
# See https://alembic.sqlalchemy.org/en/latest/batch.html#dropping-unnamed-or-named-foreign-key-constraints | ||
with op.batch_alter_table( | ||
"datasets", | ||
schema=None, | ||
naming_convention={ | ||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", | ||
}, | ||
) as batch_op: | ||
batch_op.drop_constraint("fk_datasets_experiment_id_experiments", type_="foreignkey") | ||
# Need to explicitly name the fk constraint with batch alter table | ||
batch_op.create_foreign_key( | ||
"fk_datasets_experiment_id_experiments", | ||
"experiments", | ||
["experiment_id"], | ||
["experiment_id"], | ||
ondelete="CASCADE", | ||
) | ||
else: | ||
if dialect_name == "postgresql": | ||
fk_constraint_name = "datasets_experiment_id_fkey" | ||
elif dialect_name == "mysql": | ||
fk_constraint_name = "datasets_ibfk_1" | ||
elif dialect_name == "mssql": | ||
# mssql fk constraint name at 867495a8f9d4 | ||
fk_constraint_name = "FK__datasets__experi__6477ECF3" | ||
|
||
# don't use batch alter table here so `create_foreign_key()` can be | ||
# called with `None` as the `constraint_name` and have it set | ||
# automatically based on the conventions of the sql flavor | ||
op.drop_constraint(fk_constraint_name, "datasets", type_="foreignkey") | ||
op.create_foreign_key( | ||
None, | ||
"datasets", | ||
"experiments", | ||
["experiment_id"], | ||
["experiment_id"], | ||
ondelete="CASCADE", | ||
) | ||
|
||
|
||
def downgrade(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harupy can you double check if this is okay? Running
tests/db/update_schemas.sh
is automatically removing the primary key constraint name in the mysql schema for the trace tables despite this PR not touching the trace models at all. It looks like mysql doesn't allow for primary key constraints to be named?EDIT: on second look, all named primary key constraints are already unnamed in the mysql schema, so this is expected