Skip to content

Commit

Permalink
Fix migration script for v1.2 upgrade (#651)
Browse files Browse the repository at this point in the history
### Feature or Bugfix
- Bugfix

### Detail
- migration script for upgrade to V1.2 had a mistake and is affecting
one customer. Basically the `devStrategy` and `devStages` values were
not backfilled which causes nulls in the RDS table that are not allowed
as this column should contain only non-null values.

In this PR we modify that script for customers that have not updated
yet. It is not 100% clear to me whether we should merge it, but I wanted
to raise awareness of this issue here.

### Relates
- #637 

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
dlpzx authored Aug 14, 2023
1 parent a39fd43 commit c189de4
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,61 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import orm, Column, String
from sqlalchemy.dialects import postgresql
from sqlalchemy.ext.declarative import declarative_base

# revision identifiers, used by Alembic.
revision = 'b1cdc0dc987a'
down_revision = '4392a0c9747f'
branch_labels = None
depends_on = None

Base = declarative_base()


class DataPipeline(Base):
__tablename__ = 'datapipeline'
DataPipelineUri = Column(
String, nullable=False, primary_key=True
)
devStrategy = Column(String, nullable=True)
devStages = Column(postgresql.ARRAY(String), nullable=True)


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
# Modify column types
print("Upgrade devStages and devStrategy column types. Updating nullable to True...")
op.add_column(
'datapipeline',
sa.Column('template', sa.String(), nullable=True)
)
op.alter_column(
'datapipeline',
'devStages',
existing_type=postgresql.ARRAY(sa.VARCHAR()),
nullable=True
)
op.alter_column(
'datapipeline',
'devStrategy',
existing_type=sa.VARCHAR(),
nullable=True
)
print("Backfilling values for devStages and devStrategy...")
# Backfill values
bind = op.get_bind()
session = orm.Session(bind=bind)
session.query(DataPipeline).filter(DataPipeline.devStrategy is None).update(
{DataPipeline.devStrategy: 'gitflowBlueprint'}, synchronize_session=False)

session.query(DataPipeline).filter(DataPipeline.devStages is None).update(
{DataPipeline.devStages: ['dev', 'test', 'prod']}, synchronize_session=False)
session.commit()

print("Backfilling values for devStages and devStrategy is done. Updating nullable to False...")
# Force nullable = False
op.alter_column(
'datapipeline',
'devStages',
Expand Down

0 comments on commit c189de4

Please sign in to comment.