Skip to content

Commit a4b7fff

Browse files
authored
db auto migrate (#69)
1 parent 6c477c7 commit a4b7fff

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pkg/middlewares/database/postgres.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package database
33
import (
44
"net/url"
55

6+
"github.com/machinefi/sprout-pebble-sequencer/pkg/models"
67
"github.com/xoctopus/datatypex"
78
"gorm.io/driver/postgres"
89
"gorm.io/gorm"
@@ -22,7 +23,7 @@ func (d *Postgres) SetDefault() {
2223
Host: "127.0.0.1",
2324
Port: 5432,
2425
Base: "pebble",
25-
Param: url.Values{"sslmode": []string{"disable"}},
26+
Param: url.Values{"sslmode": []string{"disable"}, "search_path": []string{"newpebble"}},
2627
}
2728
}
2829
}
@@ -34,6 +35,21 @@ func (d *Postgres) Init() error {
3435
if err != nil {
3536
return err
3637
}
38+
39+
if err := db.AutoMigrate(
40+
&models.Account{},
41+
&models.App{},
42+
&models.AppV2{},
43+
&models.Bank{},
44+
&models.BankRecord{},
45+
&models.Device{},
46+
&models.DeviceRecord{},
47+
&models.Task{},
48+
&models.Message{},
49+
); err != nil {
50+
return err
51+
}
52+
3753
d.DB = db
3854
return nil
3955
}

0 commit comments

Comments
 (0)