55 "fmt"
66 "log"
77
8+ "github.com/jackc/pgx/v5/stdlib"
9+
810 "github.com/pressly/goose/v3"
911
1012 "github.com/Permify/permify/internal/config"
@@ -29,15 +31,15 @@ func Migrate(conf config.Database) (err error) {
2931 case database .POSTGRES .String ():
3032 // Create a new Postgres database connection
3133 var db * PQDatabase.Postgres
32- db , err = PQDatabase .New (conf .URI )
34+ db , err = PQDatabase .New (conf .URI , PQDatabase . SimpleMode ( conf . SimpleMode ) )
3335 if err != nil {
3436 return err
3537 }
3638 // Ensure database connection is closed when function returns
3739 defer closeDB (db )
3840
3941 // check postgres version
40- _ , err = utils .EnsureDBVersion (db .DB )
42+ _ , err = utils .EnsureDBVersion (db .ReadPool )
4143 if err != nil {
4244 return err
4345 }
@@ -53,8 +55,10 @@ func Migrate(conf config.Database) (err error) {
5355 // Set file system for migration scripts
5456 goose .SetBaseFS (postgresMigrations )
5557
58+ pool := stdlib .OpenDBFromPool (db .WritePool )
59+
5660 // Perform migration
57- if err = goose .Up (db . DB , postgresMigrationDir ); err != nil {
61+ if err = goose .Up (pool , postgresMigrationDir ); err != nil {
5862 return err
5963 }
6064
@@ -86,8 +90,9 @@ func MigrateUp(engine, uri string) (err error) {
8690 }
8791
8892 goose .SetBaseFS (postgresMigrations )
93+ pool := stdlib .OpenDBFromPool (db .WritePool )
8994
90- if err = goose .Up (db . DB , postgresMigrationDir ); err != nil {
95+ if err = goose .Up (pool , postgresMigrationDir ); err != nil {
9196 return err
9297 }
9398
@@ -117,8 +122,9 @@ func MigrateUpTo(engine, uri string, p int64) (err error) {
117122 }
118123
119124 goose .SetBaseFS (postgresMigrations )
125+ pool := stdlib .OpenDBFromPool (db .WritePool )
120126
121- if err = goose .UpTo (db . DB , postgresMigrationDir , p ); err != nil {
127+ if err = goose .UpTo (pool , postgresMigrationDir , p ); err != nil {
122128 return err
123129 }
124130
@@ -148,8 +154,9 @@ func MigrateDown(engine, uri string) (err error) {
148154 }
149155
150156 goose .SetBaseFS (postgresMigrations )
157+ pool := stdlib .OpenDBFromPool (db .WritePool )
151158
152- if err = goose .Down (db . DB , postgresMigrationDir ); err != nil {
159+ if err = goose .Down (pool , postgresMigrationDir ); err != nil {
153160 return err
154161 }
155162
@@ -179,8 +186,9 @@ func MigrateDownTo(engine, uri string, p int64) (err error) {
179186 }
180187
181188 goose .SetBaseFS (postgresMigrations )
189+ pool := stdlib .OpenDBFromPool (db .WritePool )
182190
183- if err = goose .DownTo (db . DB , postgresMigrationDir , p ); err != nil {
191+ if err = goose .DownTo (pool , postgresMigrationDir , p ); err != nil {
184192 return err
185193 }
186194
@@ -210,8 +218,9 @@ func MigrateReset(engine, uri string) (err error) {
210218 }
211219
212220 goose .SetBaseFS (postgresMigrations )
221+ pool := stdlib .OpenDBFromPool (db .WritePool )
213222
214- if err = goose .Reset (db . DB , postgresMigrationDir ); err != nil {
223+ if err = goose .Reset (pool , postgresMigrationDir ); err != nil {
215224 return err
216225 }
217226
@@ -241,8 +250,9 @@ func MigrateStatus(engine, uri string) (err error) {
241250 }
242251
243252 goose .SetBaseFS (postgresMigrations )
253+ pool := stdlib .OpenDBFromPool (db .WritePool )
244254
245- if err = goose .Status (db . DB , postgresMigrationDir ); err != nil {
255+ if err = goose .Status (pool , postgresMigrationDir ); err != nil {
246256 return err
247257 }
248258
0 commit comments