From 8adb8c7725a8cb2f42804237662c46256a25e69f Mon Sep 17 00:00:00 2001 From: andrew-corbalt <130405742+andrew-corbalt@users.noreply.github.com> Date: Mon, 10 Nov 2025 12:15:14 -0800 Subject: [PATCH 1/2] Add EnsureSchema function to create database schema --- migrations/migration.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/migrations/migration.go b/migrations/migration.go index b53fbd1..e0553f6 100644 --- a/migrations/migration.go +++ b/migrations/migration.go @@ -244,3 +244,13 @@ func Migrate(db *sqlx.DB, migrations []NamedMigration) error { } } } + +func EnsureSchema(db *sqlx.DB, schemaName string) error { + q := fmt.Sprintf("CREATE SCHEMA IF NOT EXISTS %s", schemaName) + _, err := db.Exec(q) + if err != nil { + return fmt.Errorf("Error ensuring schema %q: %w", schemaName, err) + } + + return nil +} From f4cfc37172f159af178e3566ecd13a498b615112 Mon Sep 17 00:00:00 2001 From: andrew-corbalt <130405742+andrew-corbalt@users.noreply.github.com> Date: Tue, 11 Nov 2025 10:17:45 -0800 Subject: [PATCH 2/2] Add comment about write privileges in EnsureSchema Added comment to clarify permissions needed for EnsureSchema function. --- migrations/migration.go | 1 + 1 file changed, 1 insertion(+) diff --git a/migrations/migration.go b/migrations/migration.go index e0553f6..82fb7f5 100644 --- a/migrations/migration.go +++ b/migrations/migration.go @@ -245,6 +245,7 @@ func Migrate(db *sqlx.DB, migrations []NamedMigration) error { } } +// This function requires write privleges even if the schema already exists func EnsureSchema(db *sqlx.DB, schemaName string) error { q := fmt.Sprintf("CREATE SCHEMA IF NOT EXISTS %s", schemaName) _, err := db.Exec(q)