MCPcopy Create free account
hub / github.com/Permify/permify / MigrateUpTo

Function MigrateUpTo

internal/storage/migration.go:115–144  ·  view source on GitHub ↗

MigrateUpTo performs database migrations up to a specific version.

(engine, uri string, p int64)

Source from the content-addressed store, hash-verified

113
114// MigrateUpTo performs database migrations up to a specific version.
115func MigrateUpTo(engine, uri string, p int64) (err error) {
116 switch engine {
117 case database.POSTGRES.String():
118 var db *PQDatabase.Postgres
119 db, err = PQDatabase.New(uri)
120 if err != nil {
121 return err
122 }
123 defer closeDB(db)
124
125 goose.SetTableName(migrationsTable)
126
127 if err = goose.SetDialect(postgresDialect); err != nil {
128 return err
129 }
130
131 goose.SetBaseFS(postgresMigrations)
132 pool := stdlib.OpenDBFromPool(db.WritePool)
133
134 if err = goose.UpTo(pool, postgresMigrationDir, p); err != nil {
135 return err
136 }
137
138 return nil
139 case database.MEMORY.String():
140 return nil
141 default:
142 return fmt.Errorf("%s connection is unsupported", engine)
143 }
144}
145
146// MigrateDown undoes all database migrations, reverting the schema to the initial state.
147func MigrateDown(engine, uri string) (err error) {

Callers 1

migrateUpFunction · 0.92

Calls 2

closeDBFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected