Include "info" dict in create_table statement #1328
-
Hi, our Oracle db requires partitions for some of the tables, which we used to add using alembic with the following steps. These are based on the proposal of @zzzeek here (for nicer formatting see here). It's been a long time since I needed a change in the schema, so I only now realized that there seems to have been a regression / change in behavior. Main code: from sqlalchemy import MetaData, Column, String
from sqlalchemy.ext.declarative import declarative_base
metadata = MetaData()
Base = declarative_base(metadata=metadata)
class Table(Base):
__tablename__ = 'Table'
name = Column(String(10), primary_key=True)
__table_args__ = {'info': {'oracle_partition': "PARTITION BY ..."}} This rewriter is added as writer = rewriter.Rewriter()
@writer.rewrites(ops.CreateTableOp)
def add_info_to_table(context, revision, op):
op.kw["info"] = op.columns[0].table.info
return ops.CreateTableOp(
table_name=op.table_name,
columns=op.columns,
schema=op.schema,
_namespace_metadata=op._namespace_metadata,
_constraints_included=op._constraints_included,
**op.kw,
) We add this to the migration scripts, which adds the partition command to the created statement: import sqlalchemy as sa
from alembic import op
import textwrap
@sa.ext.compiler.compiles(sa.schema.CreateTable, "oracle")
def _add_suffixes(element, compiler, **kw): # type: ignore
text = compiler.visit_create_table(element, **kw)
if "oracle_partition" in element.element.info:
text += textwrap.dedent(element.element.info["oracle_partition"]).strip()
return text For op.create_table(
"Table",
sa.Column("name", sa.String(length=10), nullable=False),
sa.PrimaryKeyConstraint("name"),
info={"oracle_partition": "PARTITION BY ..."},
) However, for op.create_table(
"Table",
sa.Column("name", sa.String(length=10), nullable=False),
sa.PrimaryKeyConstraint("name"),
) I checked version Thanks and regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
well at the very least there's a typing error with Rewriter being sent to process_revision_directives |
Beta Was this translation helpful? Give feedback.
-
IIUC the bug here is an autogenerate rendering issue. rendering "info" overall though doesnt seem like something we would have been doing in any case, it can have anything inside of it that we would not know how to render. are you sure this used to render "info" at some point? |
Beta Was this translation helpful? Give feedback.
oh yes I guess 1ce8166 would have reversed this then since it's popping it.
issue is in #1329