Fix db upgrade with SQLAlchemy 2.0
DB schema upgrade is stuck when SQLAlchemy 2.0 is used because all operations are not executed within a transaction. Change-Id: Ief7ea81e78344ea32fb2a295f11a5d5a873251a8
This commit is contained in:
parent
fa8b7dc862
commit
f3990c6d2d
|
@ -156,11 +156,13 @@ class Connection(base.Connection):
|
|||
def upgrade(self, nocreate=False):
|
||||
cfg = self._get_alembic_config()
|
||||
cfg.conf = self.conf
|
||||
engine = enginefacade.writer.get_engine()
|
||||
with engine.begin() as connection:
|
||||
cfg.attributres['connection'] = connection
|
||||
if nocreate:
|
||||
command.upgrade(cfg, "head")
|
||||
else:
|
||||
engine = enginefacade.writer.get_engine()
|
||||
ctxt = migration.MigrationContext.configure(engine.connect())
|
||||
ctxt = migration.MigrationContext.configure(connection)
|
||||
current_version = ctxt.get_current_revision()
|
||||
if current_version is None:
|
||||
models.Base.metadata.create_all(engine, checkfirst=False)
|
||||
|
|
Loading…
Reference in New Issue