From 95baf56b61dcdc94baa5156f32ac3adb62e960df Mon Sep 17 00:00:00 2001 From: shahargl Date: Wed, 23 Oct 2024 13:48:17 +0300 Subject: [PATCH] fix: sqlite migration --- .../versions/2024-10-22-10-38_8438f041ee0e.py | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/keep/api/models/db/migrations/versions/2024-10-22-10-38_8438f041ee0e.py b/keep/api/models/db/migrations/versions/2024-10-22-10-38_8438f041ee0e.py index eae0abfc5..df34c53e8 100644 --- a/keep/api/models/db/migrations/versions/2024-10-22-10-38_8438f041ee0e.py +++ b/keep/api/models/db/migrations/versions/2024-10-22-10-38_8438f041ee0e.py @@ -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 @@ -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: