Skip to content

Commit

Permalink
lifecycle: migrate: ensure template schema exists before migrating (c…
Browse files Browse the repository at this point in the history
…herry-pick #8952) (#9022)

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

Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
  • Loading branch information
gcp-cherry-pick-bot[bot] and rissson committed Mar 25, 2024
1 parent 5f0af81 commit 49d83f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lifecycle/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,))


Expand Down
12 changes: 12 additions & 0 deletions lifecycle/system_migrations/template_schema.py
Original file line number Diff line number Diff line change
@@ -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;")

0 comments on commit 49d83f1

Please sign in to comment.