Skip to content

Commit

Permalink
fix: remove automigrate from new adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jul 1, 2024
1 parent 76a83a3 commit 5c76bca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
16 changes: 3 additions & 13 deletions adapters/gorm/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ import (

// RunMigrations is a helper function to run the migrations for the database.
func RunMigrations(db *gorm.DB) error {
err := db.AutoMigrate(
return db.AutoMigrate(
&adapters.GothAccount{},
&adapters.GothUser{},
&adapters.GothSession{},
&adapters.GothVerificationToken{},
&adapters.GothTeam{},
&adapters.GothRole{},
)
if err != nil {
return err
}

return nil
}

var _ adapters.Adapter = (*gormAdapter)(nil)
Expand All @@ -38,13 +33,8 @@ type gormAdapter struct {
}

// New ...
func New(db *gorm.DB) (*gormAdapter, error) {
err := RunMigrations(db)
if err != nil {
return nil, err
}

return &gormAdapter{db, adapters.UnimplementedAdapter{}}, nil
func New(db *gorm.DB) *gormAdapter {
return &gormAdapter{db, adapters.UnimplementedAdapter{}}
}

// CreateUser is a helper function to create a new user.
Expand Down
7 changes: 4 additions & 3 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func init() {
rootCmd.SilenceUsage = true
}

func run(ctx context.Context) error {
func run(_ context.Context) error {
log.SetFlags(0)
log.SetOutput(os.Stderr)

Expand All @@ -83,11 +83,12 @@ func run(ctx context.Context) error {
return err
}

ga, err := gorm_adapter.New(conn)
if err != nil {
if err := gorm_adapter.RunMigrations(conn); err != nil {
return err
}

ga := gorm_adapter.New(conn)

providers.RegisterProvider(github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), "http://localhost:3000/auth/github/callback"))

m := map[string]string{
Expand Down

0 comments on commit 5c76bca

Please sign in to comment.