-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update
unique_table_ownership
constraint to allow owner per ty…
…pe (#1403)
- Loading branch information
Showing
2 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
querybook/migrations/versions/299e24dcfd29_allow_unique_table_ownership_per_type.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,87 @@ | ||
"""allow unique_table_ownership per type | ||
Revision ID: 299e24dcfd29 | ||
Revises: c00f08f16065 | ||
Create Date: 2024-01-31 14:39:13.601013 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import mysql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "299e24dcfd29" | ||
down_revision = "c00f08f16065" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
ownership_table = sa.Table( | ||
"data_table_ownership", sa.MetaData(op.get_bind()), autoload=True | ||
) | ||
|
||
for constraint in ownership_table.foreign_key_constraints: | ||
op.drop_constraint(constraint.name, "data_table_ownership", type_="foreignkey") | ||
|
||
op.drop_constraint("unique_table_ownership", "data_table_ownership", type_="unique") | ||
|
||
op.create_foreign_key( | ||
"data_table_ownership_data_table_id_fk", | ||
"data_table_ownership", | ||
"data_table", | ||
["data_table_id"], | ||
["id"], | ||
ondelete="CASCADE", | ||
) | ||
op.create_foreign_key( | ||
"data_table_ownership_uid_fk", | ||
"data_table_ownership", | ||
"user", | ||
["uid"], | ||
["id"], | ||
ondelete="CASCADE", | ||
) | ||
op.create_unique_constraint( | ||
"unique_table_ownership", | ||
"data_table_ownership", | ||
["data_table_id", "uid", "type"], | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
ownership_table = sa.Table( | ||
"data_table_ownership", sa.MetaData(op.get_bind()), autoload=True | ||
) | ||
|
||
for constraint in ownership_table.foreign_key_constraints: | ||
op.drop_constraint(constraint.name, "data_table_ownership", type_="foreignkey") | ||
|
||
op.drop_constraint("unique_table_ownership", "data_table_ownership", type_="unique") | ||
|
||
op.create_foreign_key( | ||
"data_table_ownership_data_table_id_fk", | ||
"data_table_ownership", | ||
"data_table", | ||
["data_table_id"], | ||
["id"], | ||
ondelete="CASCADE", | ||
) | ||
op.create_foreign_key( | ||
"data_table_ownership_uid_fk", | ||
"data_table_ownership", | ||
"user", | ||
["uid"], | ||
["id"], | ||
ondelete="CASCADE", | ||
) | ||
op.create_unique_constraint( | ||
"unique_table_ownership", | ||
"data_table_ownership", | ||
["data_table_id", "uid"], | ||
) | ||
# ### end Alembic commands ### |
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