Skip to content

Commit

Permalink
feat: support skipping migration on db init
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed May 23, 2024
1 parent ec2af3f commit 25ab05b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ func InitDB(connection string, migrateOpts *migrate.MigrateOptions) (*dutyContex

// SetupDB runs migrations for the connection and returns a gorm.DB and a pgxpool.Pool
func SetupDB(connection string, migrateOpts *migrate.MigrateOptions) (gormDB *gorm.DB, pgxpool *pgxpool.Pool, err error) {
if migrateOpts == nil {
migrateOpts = &migrate.MigrateOptions{}
}

pgxpool, err = NewPgxPool(connection)
if err != nil {
return
Expand All @@ -215,13 +219,19 @@ func SetupDB(connection string, migrateOpts *migrate.MigrateOptions) (gormDB *go
}
defer conn.Release()

if err := conn.Ping(context.Background()); err != nil {
return nil, nil, fmt.Errorf("error pinging database: %w", err)
}

gormDB, err = NewGorm(connection, DefaultGormConfig())
if err != nil {
return
}

if err = Migrate(connection, migrateOpts); err != nil {
return
if !migrateOpts.Skip {
if err = Migrate(connection, migrateOpts); err != nil {
return
}
}

return
Expand Down
1 change: 1 addition & 0 deletions migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

type MigrateOptions struct {
Skip bool // Skip running migrations
IgnoreFiles []string
}

Expand Down
1 change: 0 additions & 1 deletion upstream/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func NewUpstreamClient(config UpstreamConfig) *UpstreamClient {
opt(client.Client)
}
return &client

}

// PushArtifacts uploads the given artifact to the upstream server.
Expand Down

0 comments on commit 25ab05b

Please sign in to comment.