Skip to content

Commit

Permalink
fix: sqlite migration
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl committed Oct 23, 2024
1 parent 124550e commit af9ba5b
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ def upgrade() -> None:
with op.batch_alter_table("provider", schema=None) as batch_op:
batch_op.alter_column("pulling_enabled", nullable=False)
else:
# Implementation for other databases
# 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=False,
server_default=sa.true(),
)
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()
)


Expand Down

0 comments on commit af9ba5b

Please sign in to comment.