We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d56090c commit 0f4a8c0Copy full SHA for 0f4a8c0
database/database.go
@@ -1,18 +1,27 @@
1
package database
2
3
import (
4
+ "fmt"
5
+
6
+ "github.com/Jetlum/WalletAlertService/models"
7
"gorm.io/driver/postgres"
8
"gorm.io/gorm"
9
)
10
-// Exported DB variable
11
var DB *gorm.DB
12
13
func InitDB(dsn string) error {
14
var err error
15
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
16
if err != nil {
- return err
17
+ return fmt.Errorf("failed to connect to database: %w", err)
18
}
19
20
+ // Run migrations
21
+ err = DB.AutoMigrate(&models.Event{}, &models.UserPreference{})
22
+ if err != nil {
23
+ return fmt.Errorf("failed to run migrations: %w", err)
24
+ }
25
26
return nil
27
0 commit comments