-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...nml/zen_stores/migrations/versions/76b6b9101a0c_add_model_version_producer_run_unique_.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,62 @@ | ||
"""Add model version producer run unique constraint [76b6b9101a0c]. | ||
Revision ID: 76b6b9101a0c | ||
Revises: 0.71.0 | ||
Create Date: 2024-12-09 11:18:59.515385 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
import sqlmodel | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "76b6b9101a0c" | ||
down_revision = "0.71.0" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
"""Upgrade database schema and/or data, creating a new revision.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("model_version", schema=None) as batch_op: | ||
batch_op.add_column( | ||
sa.Column( | ||
"is_numeric", | ||
sa.Boolean(), | ||
sa.Computed( | ||
"name == number", | ||
), | ||
nullable=True, | ||
) | ||
) | ||
batch_op.add_column( | ||
sa.Column( | ||
"producer_run_id", sqlmodel.sql.sqltypes.GUID(), nullable=True | ||
) | ||
) | ||
batch_op.create_index( | ||
"unique_numeric_version_for_pipeline_run", | ||
[ | ||
"model_id", | ||
"is_numeric", | ||
sa.text( | ||
"CASE WHEN producer_run_id IS NOT NULL THEN producer_run_id ELSE id END" | ||
), | ||
], | ||
unique=True, | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
"""Downgrade database schema and/or data back to the previous revision.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("model_version", schema=None) as batch_op: | ||
batch_op.drop_index("unique_numeric_version_for_pipeline_run") | ||
batch_op.drop_column("producer_run_id") | ||
batch_op.drop_column("is_numeric") | ||
|
||
# ### end Alembic commands ### |