Skip to content

Commit

Permalink
fix: run migrations by default
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Aug 19, 2024
1 parent a195a5f commit 1b8494c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func NewConfig(connection string) Config {
type Config struct {
Metrics bool
ConnectionString, Schema string
RunMigrations bool
SkipMigrations bool // Deprecated
RunMigrations bool // Deprecated
SkipMigrations bool
SkipMigrationFiles []string
DisableKubernetes bool
Namespace string
Expand Down
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func SetupDB(config api.Config) (gormDB *gorm.DB, pgxpool *pgxpool.Pool, err err
return
}

if config.RunMigrations {
if !config.SkipMigrations {
if err = Migrate(config); err != nil {
return
}
Expand Down
9 changes: 5 additions & 4 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func BindPFlags(flags *pflag.FlagSet) {
flags.StringVar(&DefaultConfig.Postgrest.URL, "postgrest-uri", "http://localhost:3000", "URL for the PostgREST instance to use. If localhost is supplied, a PostgREST instance will be started")
flags.StringVar(&DefaultConfig.Postgrest.LogLevel, "postgrest-log-level", "info", "PostgREST log level")
flags.StringVar(&DefaultConfig.Postgrest.JWTSecret, "postgrest-jwt-secret", "PGRST_JWT_SECRET", "JWT Secret Token for PostgREST")
flags.BoolVar(&DefaultConfig.RunMigrations, "db-migrations", false, "Run database migrations")
flags.BoolVar(&DefaultConfig.RunMigrations, "db-migrations", true, "Run database migrations")
flags.BoolVar(&DefaultConfig.SkipMigrations, "skip-migrations", false, "Skip database migrations")
flags.BoolVar(&DefaultConfig.Postgrest.Disable, "disable-postgrest", false, "Disable PostgREST. Deprecated (Use --postgrest-uri '' to disable PostgREST)")
flags.StringVar(&DefaultConfig.Postgrest.DBRole, "postgrest-role", "postgrest_api", "PostgREST role for authentication connections")
Expand All @@ -36,7 +36,7 @@ func BindPFlags(flags *pflag.FlagSet) {
flags.BoolVar(&DefaultConfig.DisableKubernetes, "disable-kubernetes", false, "Disable Kubernetes integration")
flags.BoolVar(&DefaultConfig.Metrics, "db-metrics", false, "Expose db metrics")

_ = flags.MarkDeprecated("skip-migrations", "migrations are skipped by default. Use --db-migrations to run migrations.")
_ = flags.MarkDeprecated("db-migrations", "migrations are run by default. Use --skip-migrations to skip migrations.")
}

type StartOption func(config Config) Config
Expand All @@ -63,13 +63,14 @@ var EnableMetrics = func(config Config) Config {
return config
}

var RunMigrations = func(config Config) Config {
config.RunMigrations = true
var SkipMigrations = func(config Config) Config {
config.SkipMigrations = true
return config
}

var ClientOnly = func(config Config) Config {
config.Postgrest.Disable = true
config.SkipMigrations = true
return config
}

Expand Down
6 changes: 4 additions & 2 deletions tests/setup/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func BeforeSuiteFn(args ...interface{}) context.Context {
})
}

ctx, _, err := duty.Start("test", duty.DisablePostgrest, duty.RunMigrations, duty.WithUrl(PgUrl))
ctx, _, err := duty.Start("test", duty.DisablePostgrest, duty.SkipMigrations, duty.WithUrl(PgUrl))
if err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -220,7 +220,9 @@ func NewDB(ctx context.Context, name string) (*context.Context, func(), error) {
return nil, nil, err
}

newCtx, err := duty.InitDB(api.NewConfig(strings.ReplaceAll(pgUrl, pgDbName, newName)))
newCtx, err := duty.InitDB(api.Config{
ConnectionString: strings.ReplaceAll(pgUrl, pgDbName, newName),
})
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 1b8494c

Please sign in to comment.