Skip to content

Commit

Permalink
Skip migration check
Browse files Browse the repository at this point in the history
  • Loading branch information
hiveer committed Sep 13, 2024
1 parent e6692f5 commit 7eccb0d
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions cmd/csghub-portal/cmd/start/start.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package start

import (
"context"
"fmt"
"time"

"github.com/spf13/cobra"
"opencsg.com/portal/config"
"opencsg.com/portal/pkg/database"
"opencsg.com/portal/pkg/database/migrations"
)

func init() {
Expand All @@ -19,29 +12,30 @@ var Cmd = &cobra.Command{
Use: "start",
Short: "start a server",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), 10*time.Second)
defer cancel()

config, err := config.LoadConfig()
if err != nil {
return err
}

db, err := database.NewDB(config)
if err != nil {
return fmt.Errorf("initializing DB: %w", err)
}
migrator := migrations.NewMigrator(db)

status, err := migrator.MigrationsWithStatus(ctx)
if err != nil {
return fmt.Errorf("checking migrations status: %w", err)
}
// Do not check unapplied migrations for now
// ctx, cancel := context.WithTimeout(cmd.Context(), 10*time.Second)
// defer cancel()

// config, err := config.LoadConfig()
// if err != nil {
// return err
// }

// db, err := database.NewDB(config)
// if err != nil {
// return fmt.Errorf("initializing DB: %w", err)
// }

// migrator := migrations.NewMigrator(db)
// status, err := migrator.MigrationsWithStatus(ctx)
// if err != nil {
// return fmt.Errorf("checking migrations status: %w", err)
// }
// unapplied := status.Unapplied()
// if len(unapplied) > 0 {
// return fmt.Errorf("there are %d migrations to apply: %s", len(unapplied), unapplied)
// }

unapplied := status.Unapplied()
if len(unapplied) > 0 {
return fmt.Errorf("there are %d migrations to apply: %s", len(unapplied), unapplied)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down

0 comments on commit 7eccb0d

Please sign in to comment.