I have modified the script to define the table and pass it using copy_from
according to the documentation
...
def upgrade_example():
op.create_table('example',
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint('uuid'),
...
)
with op.batch_alter_table('example', copy_from=Example.__table__) as batch_op:
batch_op.create_index(batch_op.f('ix_example_uuid'), ['uuid'], unique=True)
"alembic upgrade head --sql" fails with:
#!
INFO [alembic.env] Migrating database example
INFO [alembic.env] Writing output to example.sql
INFO [alembic.migration] Context impl SQLiteImpl.
INFO [alembic.migration] Generating static SQL
INFO [alembic.migration] Will assume non-transactional DDL.
INFO [alembic.migration] Running upgrade -> initial, empty message
Traceback (most recent call last):
File "<path>/bin/alembic", line 9, in <module>
load_entry_point('alembic==0.7.5.post2.dev0', 'console_scripts', 'alembic')()
File "<path>/lib/python/site-packages/alembic/config.py", line 439, in main
CommandLine(prog=prog).main(argv=argv)
File "<path>/lib/python/site-packages/alembic/config.py", line 433, in main
self.run_cmd(cfg, options)
File "<path>/lib/python/site-packages/alembic/config.py", line 416, in run_cmd
**dict((k, getattr(options, k)) for k in kwarg)
File "<path>/lib/python/site-packages/alembic/command.py", line 165, in upgrade
script.run_env()
File "<path>/lib/python/site-packages/alembic/script.py", line 390, in run_env
util.load_python_file(self.dir, 'env.py')
File "<path>/lib/python/site-packages/alembic/util.py", line 243, in load_python_file
module = load_module_py(module_id, path)
File "<path>/lib/python/site-packages/alembic/compat.py", line 79, in load_module_py
mod = imp.load_source(module_id, path, fp)
File "alembic/env.py", line 171, in <module>
run_migrations_offline()
File "alembic/env.py", line 112, in run_migrations_offline
context.run_migrations(engine_name=name)
File "<string>", line 7, in run_migrations
File "<path>/lib/python/site-packages/alembic/environment.py", line 742, in run_migrations
self.get_context().run_migrations(**kw)
File "<path>/lib/python/site-packages/alembic/migration.py", line 309, in run_migrations
step.migration_fn(**kw)
File "<proj>/alembic/versions/initial.py", line 23, in upgrade
globals()["upgrade_%s" % engine_name]()
File "<proj>/alembic/versions/initial.py", line 56, in upgrade_example
batch_op.create_index(batch_op.f('ix_example_uuid'), ['uuid'], unique=True)
File "<path>/lib/python2.7/contextlib.py", line 24, in __exit__
self.gen.next()
File "<path>/lib/python/site-packages/alembic/operations.py", line 320, in batch_alter_table
impl.flush()
File "<path>/lib/python/site-packages/alembic/batch.py", line 66, in flush
*self.reflect_args, **self.reflect_kwargs)
File "<path>/lib/python/site-packages/sqlalchemy/sql/schema.py", line 406, in __new__
table._init(name, metadata, *args, **kw)
File "<path>/lib/python/site-packages/sqlalchemy/sql/schema.py", line 479, in _init
self._autoload(metadata, autoload_with, include_columns)
File "<path>/lib/python/site-packages/sqlalchemy/sql/schema.py", line 489, in _autoload
autoload_with.run_callable(
AttributeError: 'MockConnection' object has no attribute 'run_callable'
Fully implemented the
:paramref:~.Operations.batch_alter_table.copy_from parameter for
batch mode, which previously was not functioning. This allows
"batch mode" to be usable in conjunction with --sql.
fixes SQLite offline batch migration fails despite copy_from #289
sqlite dialect checks for "create_index" and "drop_index" as exceptions
for "recreate" in batch mode, the same way as "add_column", so that
unnecessary table recreates don't emit for index-only operations
Migrated issue, originally created by Thomas Tanner (@ttanner)
continuing https://bitbucket.org/zzzeek/alembic/issue/287/sqlite-batch-migrations-missing-operations with https://bitbucket.org/zzzeek/alembic/commits/2af6e438c955 applied
I have modified the script to define the table and pass it using copy_from
according to the documentation
"alembic upgrade head --sql" fails with:
sqlalchemy 0.9.9, alembic 0.7.6 (master), Python 2.7.9
In the alembic source I noticed BatchOperationsImpl.copy_from is not used anywhere.
The text was updated successfully, but these errors were encountered: