Skip to content

Commit

Permalink
fix: migration
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl committed Oct 23, 2024
1 parent 3d67afb commit 6ffef33
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@ def upgrade() -> None:
batch_op.alter_column("pulling_enabled", nullable=False)
else:
# PostgreSQL and other databases implementation
with op.batch_alter_table("provider", schema=None) as batch_op:
# 1. Add the column as nullable
batch_op.add_column(
sa.Column("pulling_enabled", sa.Boolean(), nullable=True)
)
# 2. Set default value for existing rows
op.execute(
"UPDATE provider SET pulling_enabled = true WHERE pulling_enabled IS NULL"
)
# 3. Make it non-nullable
batch_op.alter_column(
"pulling_enabled", nullable=False, server_default=sa.true()
)
# 1. Add the column as nullable
op.add_column(
"provider", sa.Column("pulling_enabled", sa.Boolean(), nullable=True)
)
# 2. Set default value for existing rows
op.execute(
"UPDATE provider SET pulling_enabled = true WHERE pulling_enabled IS NULL"
)
# 3. Make it non-nullable with default
op.alter_column(
"provider",
"pulling_enabled",
existing_type=sa.Boolean(),
nullable=False,
server_default=sa.true(),
)


def downgrade() -> None:
Expand Down

0 comments on commit 6ffef33

Please sign in to comment.