Fix restore compat check reporting empty schema heads
alembic.ini is a Flask-Migrate config with no script_location, so ScriptDirectory.from_config raised and _current_schema_revisions swallowed it and returned no heads. Every set then failed the subset check and was wrongly blocked as taken on a newer schema than the running code. Set script_location to the migrations directory - the same versions tree the manifest scans - so live heads resolve and compatible sets restore.
This commit is contained in:
@@ -113,11 +113,17 @@ def _current_schema_revisions():
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
root = current_app.root_path
|
root = current_app.root_path
|
||||||
ini = os.path.join(os.path.dirname(root), 'migrations', 'alembic.ini')
|
migrations = os.path.join(os.path.dirname(root), 'migrations')
|
||||||
|
ini = os.path.join(migrations, 'alembic.ini')
|
||||||
if not os.path.isfile(ini):
|
if not os.path.isfile(ini):
|
||||||
return {}
|
return {}
|
||||||
try:
|
try:
|
||||||
config = Config(ini)
|
config = Config(ini)
|
||||||
|
# This is a Flask-Migrate project: alembic.ini carries no
|
||||||
|
# script_location (it is set at runtime), so ScriptDirectory.from_config
|
||||||
|
# would raise and leave every set reading as incompatible. Point it at
|
||||||
|
# the migrations directory - the same versions tree manifest.py scans.
|
||||||
|
config.set_main_option('script_location', migrations)
|
||||||
script = ScriptDirectory.from_config(config)
|
script = ScriptDirectory.from_config(config)
|
||||||
return {'core': list(script.get_heads())}
|
return {'core': list(script.get_heads())}
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user