SQLite STRICT is not propagated in batch mode #1756
-
|
Hi, SQLite supports the Specs:
Sample model: from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import sqlalchemy as sa
class Base(DeclarativeBase):
type_annotation_map = {str: sa.TEXT}
class User(Base):
__tablename__ = "USER"
__table_args__ = {"sqlite_with_rowid": False, "sqlite_strict": True}
id: Mapped[int] = mapped_column(primary_key=True)
user_name: Mapped[str] = mapped_column("USER_NAME", unique=True)Steps to reproduce:
"""empty message
Revision ID: f7f7a256d2e7
Revises:
Create Date: 2025-11-27 10:57:03.994674
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'f7f7a256d2e7'
down_revision: Union[str, Sequence[str], None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('USER',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('USER_NAME', sa.TEXT(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('USER_NAME'),
sqlite_strict=True,
sqlite_with_rowid=False
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('USER')
# ### end Alembic commands ###
"""empty message
Revision ID: 1bfe725a1b85
Revises: e097f33239b9
Create Date: 2025-11-27 10:51:10.369671
"""
"""empty message
Revision ID: bf91adff8af4
Revises: f7f7a256d2e7
Create Date: 2025-11-27 10:57:39.134370
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'bf91adff8af4'
down_revision: Union[str, Sequence[str], None] = 'f7f7a256d2e7'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('USER', schema=None) as batch_op:
batch_op.drop_column('USER_NAME')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('USER', schema=None) as batch_op:
batch_op.add_column(sa.Column('USER_NAME', sa.TEXT(), nullable=False))
# ### end Alembic commands ###
Actual result: Keywords |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
|
hi - I would classify this as a bug in batch mode, as it needs to recreate the table with all original options. |
Beta Was this translation helpful? Give feedback.
the ModifyTableOps object doesn't carry around the actual Table because it's usually intended to render "ALTER TABLE". "batch" mode was an added-on feature that I only added after people hounded me for many years to add it (I think the real bug is that SQLite doesnt support proper ALTER TABLE). It would be a more involved change since it needs to alter the structure of ModifyTableOps to carry around these options since and also all the autogenerate "compare" cases would need to locate the correct table and pass it in. im not opposed to someone working on this though.
if you're using STRICT for all tables you can also just force it on using a simple rewriter recipe.