我正在尝试以编程方式创建修订,同时以编程方式进行操作。似乎应该使用MigrationScript
来实现此目的,但是我看不到任何将脚本传递给command.revision
的简单方法。参数process_revision_directives
至少使用MigrationScript
,但据我所知,修改脚本的目的不是简单地将其传递给修订版,并且它需要此时不需要的其他对象
这是我到目前为止所拥有的:
from alembic.operations.ops import MigrationScript, CreateTableOp, DropTableOp, UpgradeOps, DowngradeOps
from alembic.config import Config
from alembic.command import revision
upgrade_ops = UpgradeOps([CreateTableOp.from_table(model.__table__)])
downgrade_ops = DowngradeOps([DropTableOp.from_table(model.__table__)])
migration_script = MigrationScript(rev_id=None, upgrade_ops=upgrade_ops,
downgrade_ops=downgrade_ops)
ini_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../alembic.ini'))
config = Config(ini_path)
# How do I use MigrationScript here?
revision(config, message="test revision")