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
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions src/zenml/models/v2/core/pipeline_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class PipelineDeploymentResponseMetadata(WorkspaceScopedResponseMetadata):
client_environment: Dict[str, str] = Field(
default={}, title="The client environment for this deployment."
)
client_version: str = Field(
client_version: Optional[str] = Field(
title="The version of the ZenML installation on the client side."
)
server_version: str = Field(
server_version: Optional[str] = Field(
title="The version of the ZenML installation on the server side."
)
pipeline: Optional[PipelineResponse] = Field(
Expand Down Expand Up @@ -219,7 +219,7 @@ def client_environment(self) -> Dict[str, str]:
return self.get_metadata().client_environment

@property
def client_version(self) -> str:
def client_version(self) -> Optional[str]:
"""The `client_version` property.

Returns:
Expand All @@ -228,7 +228,7 @@ def client_version(self) -> str:
return self.get_metadata().client_version

@property
def server_version(self) -> str:
def server_version(self) -> Optional[str]:
"""The `server_version` property.

Returns:
Expand Down
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