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

fix(migrations): sqlite migration #2275

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""add pulling_enabled

Revision ID: 8438f041ee0e
Revises: 83c1020be97d
Create Date: 2024-10-22 10:38:29.857284

"""

import sqlalchemy as sa
Expand All @@ -16,13 +14,41 @@
depends_on = None


def is_sqlite():
"""Check if we're running on SQLite"""
bind = op.get_bind()
return bind.engine.name == "sqlite"


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("provider", schema=None) as batch_op:
batch_op.add_column(
sa.Column("pulling_enabled", sa.Boolean(), nullable=False, default=True)
)
# ### end Alembic commands ###
if is_sqlite():
# SQLite specific implementation
with op.batch_alter_table("provider", schema=None) as batch_op:
# First add the column as nullable with a default value
batch_op.add_column(
sa.Column(
"pulling_enabled",
sa.Boolean(),
server_default=sa.true(),
nullable=True,
)
)

# Then make it not nullable if needed
with op.batch_alter_table("provider", schema=None) as batch_op:
batch_op.alter_column("pulling_enabled", nullable=False)
else:
# Implementation for other databases
with op.batch_alter_table("provider", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"pulling_enabled",
sa.Boolean(),
nullable=False,
server_default=sa.true(),
)
)


def downgrade() -> None:
Expand Down
Loading