forked from mlflow/mlflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cascading behavior for trace tag table (mlflow#12102)
Signed-off-by: B-Step62 <yuki.watanabe@databricks.com>
- Loading branch information
Showing
8 changed files
with
58 additions
and
13 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
mlflow/store/db_migrations/versions/5b0e9adcef9c_add_cascade_deletion_to_trace_tables_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,37 @@ | ||
"""add cascade deletion to trace tables foreign keys | ||
Revision ID: 5b0e9adcef9c | ||
Revises: 867495a8f9d4 | ||
Create Date: 2024-05-22 17:44:24.597019 | ||
""" | ||
from alembic import op | ||
from mlflow.store.tracking.dbmodels.models import SqlTraceInfo, SqlTraceRequestMetadata, SqlTraceTag | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '5b0e9adcef9c' | ||
down_revision = '867495a8f9d4' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
tables = [SqlTraceTag.__tablename__, SqlTraceRequestMetadata.__tablename__] | ||
for table in tables: | ||
fk_tag_constaint_name = f"fk_{table}_request_id" | ||
# We have to use batch_alter_table as SQLite does not support ALTER outside of a batch operation. | ||
with op.batch_alter_table(table, schema=None) as batch_op: | ||
batch_op.drop_constraint(fk_tag_constaint_name, type_="foreignkey") | ||
batch_op.create_foreign_key( | ||
fk_tag_constaint_name, | ||
SqlTraceInfo.__tablename__, | ||
["request_id"], | ||
["request_id"], | ||
# Add cascade deletion to the foreign key constraint. This is the only change in this migration. | ||
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