From 5c76bca841adf7283e37328f4a675f896b5c5c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Mon, 1 Jul 2024 19:35:33 +0000 Subject: [PATCH] fix: remove automigrate from new adapter --- adapters/gorm/gorm.go | 16 +++------------- examples/main.go | 7 ++++--- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/adapters/gorm/gorm.go b/adapters/gorm/gorm.go index bf6c048..091560a 100644 --- a/adapters/gorm/gorm.go +++ b/adapters/gorm/gorm.go @@ -14,7 +14,7 @@ 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{}, @@ -22,11 +22,6 @@ func RunMigrations(db *gorm.DB) error { &adapters.GothTeam{}, &adapters.GothRole{}, ) - if err != nil { - return err - } - - return nil } var _ adapters.Adapter = (*gormAdapter)(nil) @@ -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. diff --git a/examples/main.go b/examples/main.go index fca6817..560f802 100644 --- a/examples/main.go +++ b/examples/main.go @@ -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) @@ -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{