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

Alembic migration fix for databases with scheduled pipelines with 2+ runs #2072

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sqlmodel
from alembic import op
from sqlalchemy.dialects import mysql
from sqlalchemy.engine.base import Connection
from sqlalchemy.sql import text

# revision identifiers, used by Alembic.
Expand All @@ -21,21 +22,41 @@
def upgrade() -> None:
"""Upgrade database schema and/or data, creating a new revision."""
# ### commands auto generated by Alembic - please adjust! ###
bind: Connection = op.get_bind()
column_info = sa.inspect(bind).get_columns("pipeline_deployment")
columns = [c["name"] for c in column_info]

with op.batch_alter_table("pipeline_deployment", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
if "client_version" not in columns:
batch_op.add_column(
sa.Column(
"client_version",
sqlmodel.sql.sqltypes.AutoString(),
nullable=True,
)
)
else:
batch_op.alter_column(
"client_version",
sqlmodel.sql.sqltypes.AutoString(),
existing_type=sqlmodel.sql.sqltypes.AutoString(),
nullable=True,
)
)
batch_op.add_column(
sa.Column(

if "server_version" not in columns:
batch_op.add_column(
sa.Column(
"server_version",
sqlmodel.sql.sqltypes.AutoString(),
nullable=True,
)
)
else:
batch_op.alter_column(
"server_version",
sqlmodel.sql.sqltypes.AutoString(),
existing_type=sqlmodel.sql.sqltypes.AutoString(),
nullable=True,
)
)

batch_op.alter_column(
"pipeline_configuration",
existing_type=sa.TEXT(),
Expand All @@ -52,7 +73,7 @@ def upgrade() -> None:
"""
UPDATE pipeline_deployment
SET client_version = (
SELECT pipeline_run.client_version
SELECT max(pipeline_run.client_version)
bcdurak marked this conversation as resolved.
Show resolved Hide resolved
FROM pipeline_run
WHERE pipeline_run.deployment_id = pipeline_deployment.id
)
Expand All @@ -69,7 +90,7 @@ def upgrade() -> None:
"""
UPDATE pipeline_deployment
SET server_version = (
SELECT pipeline_run.server_version
SELECT max(pipeline_run.server_version)
FROM pipeline_run
WHERE pipeline_run.deployment_id = pipeline_deployment.id
)
Expand Down
Loading