From 0551dc70d83f621156e0713b4b92a10c09a8695d Mon Sep 17 00:00:00 2001 From: Anna Baker Date: Mon, 31 Aug 2026 22:34:15 -0400 Subject: [PATCH 1/4] chore: add support for verbose flag to the migration tool to see a list of successful migrations --- CONTRIBUTING.md | 5 +++++ Makefile | 2 +- cmd/migrate_cmd.go | 28 +++++++++++++++++++--------- cmd/root_cmd.go | 1 + hack/migrate.sh | 3 +-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2e955d778d..8d1f8c53da 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -406,6 +406,11 @@ If you need to run any new migrations: make migrate_test ``` +This passes `--verbose` to the `migrate` command, which logs the name of each +migration as it is applied. `make migrate_dev` applies the same migrations +without verbose logging, and `make test` stays at the quiet log level set in +`hack/test.env`. + ## Testing Currently, we don't use a separate test database, so the same database created when installing Auth to run locally is used. diff --git a/Makefile b/Makefile index 995d5a93e9..8fadefd83d 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,7 @@ migrate_dev: ## Run database migrations for development. hack/migrate.sh postgres migrate_test: ## Run database migrations for test. - hack/migrate.sh postgres + hack/migrate.sh postgres --verbose test: auth ## Run tests. go test -failfast $(CHECK_FILES) -coverprofile=coverage.out -coverpkg ./... -p 1 -race -v -count=1 diff --git a/cmd/migrate_cmd.go b/cmd/migrate_cmd.go index 511f53b27d..235ae9acd8 100644 --- a/cmd/migrate_cmd.go +++ b/cmd/migrate_cmd.go @@ -2,6 +2,7 @@ package cmd import ( "embed" + "fmt" "net/url" "os" @@ -14,6 +15,8 @@ import ( var EmbeddedMigrations embed.FS +var migrateVerbose bool + var migrateCmd = cobra.Command{ Use: "migrate", Long: "Migrate database strucutures. This will create new tables and add missing columns and indexes.", @@ -40,16 +43,23 @@ func migrate(cmd *cobra.Command, args []string) { log.Fatalf("Failed to parse log level: %+v", err) } log.SetLevel(level) - if level == logrus.DebugLevel { - // Set to true to display query info - pop.Debug = true - } - if level != logrus.DebugLevel { - var noopLogger = func(lvl logging.Level, s string, args ...interface{}) { + } + + switch { + case log.Level == logrus.DebugLevel: + pop.Debug = true + case migrateVerbose: + pop.SetLogger(func(lvl logging.Level, s string, args ...interface{}) { + if lvl == logging.SQL || lvl == logging.Debug { + return } - // Hide pop migration logging - pop.SetLogger(noopLogger) - } + if len(args) > 0 { + s = fmt.Sprintf(s, args...) + } + fmt.Println(s) + }) + case globalConfig.Logging.Level != "": + pop.SetLogger(func(logging.Level, string, ...interface{}) {}) } q := u.Query() diff --git a/cmd/root_cmd.go b/cmd/root_cmd.go index 1b8607328e..66128086ef 100644 --- a/cmd/root_cmd.go +++ b/cmd/root_cmd.go @@ -28,6 +28,7 @@ func RootCommand() *cobra.Command { rootCmd.AddCommand(&serveCmd, &migrateCmd, &versionCmd, adminCmd()) rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "base configuration file to load") rootCmd.PersistentFlags().StringVarP(&watchDir, "config-dir", "d", "", "directory containing a sorted list of config files to watch for changes") + migrateCmd.Flags().BoolVarP(&migrateVerbose, "verbose", "v", false, "print the name of each migration as it is applied") return &rootCmd } diff --git a/hack/migrate.sh b/hack/migrate.sh index 2d1f0e5e84..42ca171d5e 100755 --- a/hack/migrate.sh +++ b/hack/migrate.sh @@ -3,10 +3,9 @@ DB_ENV=$1 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DATABASE="$DIR/database.yml" export GOTRUE_DB_DRIVER="postgres" export GOTRUE_DB_DATABASE_URL="postgres://supabase_auth_admin:root@localhost:5432/$DB_ENV" export GOTRUE_DB_MIGRATIONS_PATH=$DIR/../migrations -go run main.go migrate -c $DIR/test.env +go run main.go migrate -c "$DIR/test.env" "${@:2}" From b8b6f8f9572c6e231a3fb88c201c66886d2dbcee Mon Sep 17 00:00:00 2001 From: Anna Baker Date: Mon, 31 Aug 2026 22:54:00 -0400 Subject: [PATCH 2/4] chore: update comment on CONTRIBUTING.md --- CONTRIBUTING.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8d1f8c53da..cd139e4bf3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -407,9 +407,7 @@ make migrate_test ``` This passes `--verbose` to the `migrate` command, which logs the name of each -migration as it is applied. `make migrate_dev` applies the same migrations -without verbose logging, and `make test` stays at the quiet log level set in -`hack/test.env`. +migration as it is applied. ## Testing From 590a7db642a2d02b38292e5887afc016d52f659f Mon Sep 17 00:00:00 2001 From: Anna Baker Date: Tue, 1 Sep 2026 12:35:04 -0400 Subject: [PATCH 3/4] chore: extract migration logging setup into named functions --- cmd/migrate_cmd.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/cmd/migrate_cmd.go b/cmd/migrate_cmd.go index 235ae9acd8..42f21fa736 100644 --- a/cmd/migrate_cmd.go +++ b/cmd/migrate_cmd.go @@ -23,6 +23,21 @@ var migrateCmd = cobra.Command{ Run: migrate, } +// popProgressLogger prints pop's migration progress, one line per applied +// migration, and hides SQL statement logging. +func popProgressLogger(lvl logging.Level, s string, args ...interface{}) { + if lvl == logging.SQL || lvl == logging.Debug { + return + } + if len(args) > 0 { + s = fmt.Sprintf(s, args...) + } + fmt.Println(s) +} + +// popNoopLogger hides pop migration logging. +func popNoopLogger(logging.Level, string, ...interface{}) {} + func migrate(cmd *cobra.Command, args []string) { globalConfig := loadGlobalConfig(cmd.Context()) u, err := url.Parse(globalConfig.DB.URL) @@ -45,21 +60,16 @@ func migrate(cmd *cobra.Command, args []string) { log.SetLevel(level) } + // Decide what pop prints while migrations run, from most to least + // output: debug shows everything, --verbose shows progress only, any + // other configured level hides migration logging entirely. switch { case log.Level == logrus.DebugLevel: pop.Debug = true case migrateVerbose: - pop.SetLogger(func(lvl logging.Level, s string, args ...interface{}) { - if lvl == logging.SQL || lvl == logging.Debug { - return - } - if len(args) > 0 { - s = fmt.Sprintf(s, args...) - } - fmt.Println(s) - }) + pop.SetLogger(popProgressLogger) case globalConfig.Logging.Level != "": - pop.SetLogger(func(logging.Level, string, ...interface{}) {}) + pop.SetLogger(popNoopLogger) } q := u.Query() From f8bf61cad791ac34f9dc17ff24672e4dc9baec10 Mon Sep 17 00:00:00 2001 From: Anna Baker Date: Tue, 1 Sep 2026 12:37:54 -0400 Subject: [PATCH 4/4] chore: remove unnecessary comments --- cmd/migrate_cmd.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmd/migrate_cmd.go b/cmd/migrate_cmd.go index 42f21fa736..2790cef84f 100644 --- a/cmd/migrate_cmd.go +++ b/cmd/migrate_cmd.go @@ -23,8 +23,6 @@ var migrateCmd = cobra.Command{ Run: migrate, } -// popProgressLogger prints pop's migration progress, one line per applied -// migration, and hides SQL statement logging. func popProgressLogger(lvl logging.Level, s string, args ...interface{}) { if lvl == logging.SQL || lvl == logging.Debug { return @@ -35,7 +33,6 @@ func popProgressLogger(lvl logging.Level, s string, args ...interface{}) { fmt.Println(s) } -// popNoopLogger hides pop migration logging. func popNoopLogger(logging.Level, string, ...interface{}) {} func migrate(cmd *cobra.Command, args []string) { @@ -60,9 +57,6 @@ func migrate(cmd *cobra.Command, args []string) { log.SetLevel(level) } - // Decide what pop prints while migrations run, from most to least - // output: debug shows everything, --verbose shows progress only, any - // other configured level hides migration logging entirely. switch { case log.Level == logrus.DebugLevel: pop.Debug = true