lifecycle: migrate: ensure template schema exists before migrating (#8952)

This commit is contained in:
Marc 'risson' Schmitt
2024-03-25 13:11:02 +01:00
committed by GitHub
parent 285dc8cff0
commit 15c7be1979
2 changed files with 13 additions and 0 deletions

View File

@ -64,6 +64,7 @@ def release_lock(cursor: Cursor):
"""Release database lock"""
if not LOCKED:
return
LOGGER.info("releasing database lock")
cursor.execute("SELECT pg_advisory_unlock(%s)", (ADV_LOCK_UID,))

View File

@ -0,0 +1,12 @@
from lifecycle.migrate import BaseMigration
class Migration(BaseMigration):
def needs_migration(self) -> bool:
self.cur.execute(
"SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'template';"
)
return not bool(self.cur.rowcount)
def run(self):
self.cur.execute("CREATE SCHEMA IF NOT EXISTS template; COMMIT;")