sqlalchemy / alembic

A database migrations tool for SQLAlchemy.
MIT License
2.89k stars 249 forks source link

Migration autogeneration should respect schemas defined using quoted_name #1526

Open characat0 opened 2 months ago

characat0 commented 2 months ago

Describe the bug When defining a table, schemas defined using quoted_name should be present on the migration generated code.

Expected behavior The schema present in the migration file should be defined using quoted_name too

To Reproduce Define a class using the snipped provided, then run alembic revision --autogenerate and check the generated migration operations

from sqlalchemy.orm import DeclarativeBase
from sqlalchemy import quoted_name

class Base(DeclarativeBase):
    pass

class Example(Base):
    __table_args__ = {'schema': quoted_name('database.schema', quote=False)}
    example_field = Column(Integer, primary_key=True)

Actual behaviour

    op.create_table('example',
    sa.Column('example_field', sa.Integer()),
    sa.PrimaryKeyConstraint('account_id'),
    schema='database.schema'
    )

Expected behaviour

    op.create_table('example',
    sa.Column('example_field', sa.Integer()),
    sa.PrimaryKeyConstraint('account_id'),
    schema=quoted_name('database.schema', quote=False)
    )

Versions.

Additional context Im using the databricks sql connector 3.3.0

Have a nice day!