diff --git a/lifecycle/migrate.py b/lifecycle/migrate.py index 6dceb6b007..1dac197119 100755 --- a/lifecycle/migrate.py +++ b/lifecycle/migrate.py @@ -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,)) diff --git a/lifecycle/system_migrations/template_schema.py b/lifecycle/system_migrations/template_schema.py new file mode 100644 index 0000000000..9ab53c0605 --- /dev/null +++ b/lifecycle/system_migrations/template_schema.py @@ -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;")