fix: keep migration objects on stable role
All checks were successful
Build and Publish Container Image / build-and-push (push) Successful in 38s

This commit is contained in:
tegwick 2026-08-21 00:27:54 +02:00
parent 749461b97b
commit d2a7fe3151
3 changed files with 17 additions and 3 deletions

View file

@ -17,21 +17,31 @@ def main() -> None:
default="/app/migrations/postgres/0001_tenant_store.sql",
help="SQL migration file",
)
parser.add_argument(
"--role",
default=os.getenv("TENANT_ENGINE_MIGRATION_ROLE", ""),
help="stable group role that must own objects created by a leased login",
)
args = parser.parse_args()
if not args.url_file:
parser.error("--url-file or TENANT_ENGINE_MIGRATION_DATABASE_URL_FILE is required")
try:
import psycopg
from psycopg import sql as psycopg_sql
except ImportError as exc: # pragma: no cover - deployment guard
raise RuntimeError("install tenant-engine[postgres] to run migrations") from exc
dsn = Path(args.url_file).read_text(encoding="utf-8").strip()
if not dsn:
raise RuntimeError("migration database URL file is empty")
sql = Path(args.migration).read_text(encoding="utf-8")
migration_sql = Path(args.migration).read_text(encoding="utf-8")
with psycopg.connect(dsn, autocommit=True) as connection:
connection.execute(sql)
if args.role:
connection.execute(
psycopg_sql.SQL("SET ROLE {}").format(psycopg_sql.Identifier(args.role))
)
connection.execute(migration_sql)
if __name__ == "__main__":