Jun 28 - Fix issue with missing table - Tenant branding error
This commit is contained in:
@@ -247,6 +247,33 @@ def _cmd_heads(_args):
|
||||
return 0
|
||||
|
||||
|
||||
def _cmd_stamp(args):
|
||||
"""Stamp tenant DB(s) to a specific revision without running migrations.
|
||||
|
||||
Use this to rewind a mistakenly-stamped tenant so a subsequent `upgrade`
|
||||
will actually replay the missing migration. Example:
|
||||
|
||||
python -m control.tenant_migrate stamp --tenant gov phase32_device_token_columns
|
||||
python -m control.tenant_migrate upgrade --tenant gov
|
||||
"""
|
||||
tenants = _select_tenants(args.tenant)
|
||||
if not tenants:
|
||||
print(f'No matching tenants for --tenant {args.tenant}.')
|
||||
return 0
|
||||
failures = 0
|
||||
for t in tenants:
|
||||
try:
|
||||
cfg = _make_config(t.db_uri)
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
command.stamp(cfg, args.revision)
|
||||
rev = current_revision(t.db_uri)
|
||||
print(f' [ok] {t.slug} (id={t.id}) stamped -> {rev}')
|
||||
except Exception as e:
|
||||
failures += 1
|
||||
print(f' [FAIL] {t.slug} (id={t.id}): {type(e).__name__}: {e}')
|
||||
return 1 if failures else 0
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(prog='control.tenant_migrate',
|
||||
description='Per-tenant migration runner')
|
||||
@@ -265,6 +292,11 @@ def main(argv=None):
|
||||
p_boot.add_argument('--tenant', required=True, help="'all', or a tenant id or slug")
|
||||
p_boot.set_defaults(func=_cmd_bootstrap)
|
||||
|
||||
p_stamp = sub.add_parser('stamp', help='Stamp tenant DB(s) to a specific revision (no migrations run)')
|
||||
p_stamp.add_argument('--tenant', required=True, help="'all', or a tenant id or slug")
|
||||
p_stamp.add_argument('revision', help='Alembic revision id (e.g. phase32_device_token_columns)')
|
||||
p_stamp.set_defaults(func=_cmd_stamp)
|
||||
|
||||
sub.add_parser('heads', help='Show the chain head revision').set_defaults(func=_cmd_heads)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
Reference in New Issue
Block a user