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__
Doing the full automigration seems overkill, but if it's considerably
easier then it's preferable. If I go this route It's not clear to me how to
avoid env.py and instead run this other context with the new include_object.
Any help would be appreciated.
Zac
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.