Skip to content

Commit e358da5

Browse files
authored
feat: use embedded migrations for migrate command (#1843)
Embeds the DB migrations in the executable. Instead of a tarball only a single file can be used to start Supabase Auth. This has added benefits in the Supabase platform for upgrades. See internal discussion.
1 parent 7de6bfb commit e358da5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

cmd/migrate_cmd.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"embed"
45
"fmt"
56
"net/url"
67
"os"
@@ -12,6 +13,8 @@ import (
1213
"github.com/spf13/cobra"
1314
)
1415

16+
var EmbeddedMigrations embed.FS
17+
1518
var migrateCmd = cobra.Command{
1619
Use: "migrate",
1720
Long: "Migrate database strucutures. This will create new tables and add missing columns and indexes.",
@@ -76,11 +79,14 @@ func migrate(cmd *cobra.Command, args []string) {
7679
log.Fatalf("%+v", errors.Wrap(err, "checking database connection"))
7780
}
7881

79-
log.Debugf("Reading migrations from %s", globalConfig.DB.MigrationsPath)
80-
mig, err := pop.NewFileMigrator(globalConfig.DB.MigrationsPath, db)
82+
log.Debugf("Reading migrations from executable")
83+
box, err := pop.NewMigrationBox(EmbeddedMigrations, db)
8184
if err != nil {
8285
log.Fatalf("%+v", errors.Wrap(err, "creating db migrator"))
8386
}
87+
88+
mig := box.Migrator
89+
8490
log.Debugf("before status")
8591

8692
if log.Level == logrus.DebugLevel {

main.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"embed"
56
"os/signal"
67
"sync"
78
"syscall"
@@ -12,11 +13,16 @@ import (
1213
"github.com/supabase/auth/internal/observability"
1314
)
1415

16+
//go:embed migrations/*
17+
var embeddedMigrations embed.FS
18+
1519
func init() {
1620
logrus.SetFormatter(&logrus.JSONFormatter{})
1721
}
1822

1923
func main() {
24+
cmd.EmbeddedMigrations = embeddedMigrations
25+
2026
execCtx, execCancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT)
2127
defer execCancel()
2228

0 commit comments

Comments
 (0)