Hello, I'm trying to create a revision programatically with the operations also made programatically. I've been trying this hackish approach below, which I now think probably isn't the right way to go due to the internals of AutogenContext, which seems required for rendering.
Here's what I have so far:
upgrade_ops = UpgradeOps([CreateTableOp.from_table(model.__table__)])
downgrade_ops = DowngradeOps([DropTableOp.from_table(model.__table__)])
command_args = dict(
message="create table " + tname,
autogenerate=False,
sql=False,
head="head",
splice=False,
branch_label=None,
version_path=None,
rev_id=rev_id(),
depends_on=None
)
script_args = {k:v for k, v in command_args.items() if k != "sql" and k != "autogenerate"}
migration_script = MigrationScript(upgrade_ops=upgrade_ops,
downgrade_ops=downgrade_ops, **script_args)
migration_script._needs_render = True
ini_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../alembic.ini'))
config = Config(ini_path, ini_section=table['schema'])
script_directory=ScriptDirectory.from_config(config)
revision = RevisionContext(config, script_directory, command_args)
revision._last_autogen_context = SimpleNamespace(imports=set())
revision._to_script(migration_script)My other thought is to use EnvironmentContext and run a full automigration with include_object set to something like
lambda o: o is model.__table__You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/4PbFyB1ZVi0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.