fix(migrations): run migrations in the system scope and repair skipped data

Row-level security hid every row from the data changes in migrations
00009 and 00012: existing members did not receive the Viewer role and
the built-in Admin role lacked tokens.manage. Built-in roles were also
not writable in the system scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 01:28:43 +01:00
1 parent 5f42e3e650
commit 7bb4afa04a
3 files changed
+67 -2

No files matched your search

+8 -2
View File
@@ -9,7 +9,8 @@ import (
"fmt"
"io/fs"
_ "github.com/jackc/pgx/v5/stdlib" // registers the "pgx" database/sql driver
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/stdlib"
"github.com/pressly/goose/v3"
"github.com/pressly/goose/v3/lock"
)
@@ -21,11 +22,16 @@ var files embed.FS
// a rolling deploy serialize instead of racing.
const lockID = 0x7570746d
// newProvider connects with app.scope=system as a session default: tables
// are under row-level security, and data changes in migrations would
// otherwise silently affect no rows.
func newProvider(dsn string) (*goose.Provider, *sql.DB, error) {
db, err := sql.Open("pgx", dsn)
cfg, err := pgx.ParseConfig(dsn)
if err != nil {
return nil, nil, err
}
cfg.RuntimeParams["app.scope"] = "system"
db := stdlib.OpenDB(*cfg)
sub, err := fs.Sub(files, "sql")
if err != nil {
return nil, nil, err