Support optional schema creation in database migrators#4911
Conversation
Add an opt-in MigrationConfig to the scheduler and lookout migrators that, when configured, ensures the target schema exists and runs migrations inside it. Supports a two-role pattern where a separate "schema-creator" role runs CREATE SCHEMA and GRANT, while a least-privileged migrator role runs the DDL. Identifier interpolation goes through pgx.Identifier.Sanitize() with a non-empty + 63-byte length check. Default behaviour is unchanged when MigrationConfig is unset. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Maurice Yap <mauriceyap@hotmail.co.uk>
Greptile SummaryThis PR introduces optional schema-scoped migrations for the scheduler and lookout migrators via a new
Confidence Score: 5/5This PR is safe to merge. The previously flagged pool-vs-single-connection bug in the lookout migrator is correctly resolved, and the new schema creation logic is well-guarded with identifier sanitization and idempotent SQL. The core concern from the previous review round — lookout's migrate using OpenPgxPool so SET search_path would silently not apply to subsequent migration queries — is properly fixed by switching to OpenPgxConn with a defer db.Close. The new PrepareSchema helper uses pgx.Identifier.Sanitize() for all identifier interpolation, validates both schema and role names against Postgres's 63-byte limit, and the two-role GRANT path is idempotent. The TxBeginner abstraction in ApplyPartitioner is structurally compatible with pgx.TxStarter so it compiles and runs correctly with a *pgx.Conn. No files require special attention. Important Files Changed
Reviews (3): Last reviewed commit: "comments" | Re-trigger Greptile |
Add an opt-in MigrationConfig to the scheduler and lookout migrators that, when configured, ensures the target schema exists and runs migrations inside it. Supports a two-role pattern where a separate "schema-creator" role runs CREATE SCHEMA and GRANT, while a least-privileged migrator role runs the DDL. Identifier interpolation goes through pgx.Identifier.Sanitize() with a non-empty + 63-byte length check.
Default behaviour is unchanged when MigrationConfig is unset.