2022-05-19 07:49:32 +00:00
|
|
|
package sqlite
|
2021-09-21 01:48:52 +00:00
|
|
|
|
|
|
|
import (
|
2022-05-19 07:49:32 +00:00
|
|
|
"context"
|
2021-09-21 01:48:52 +00:00
|
|
|
|
2022-07-13 06:30:54 +00:00
|
|
|
"github.com/jmoiron/sqlx"
|
2021-09-21 01:48:52 +00:00
|
|
|
)
|
|
|
|
|
2022-07-13 06:30:54 +00:00
|
|
|
type customMigrationFunc func(ctx context.Context, db *sqlx.DB) error
|
2021-09-21 01:48:52 +00:00
|
|
|
|
2022-07-13 06:30:54 +00:00
|
|
|
func RegisterPostMigration(schemaVersion uint, fn customMigrationFunc) {
|
|
|
|
v := postMigrations[schemaVersion]
|
|
|
|
v = append(v, fn)
|
|
|
|
postMigrations[schemaVersion] = v
|
2021-09-21 01:48:52 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 06:30:54 +00:00
|
|
|
func RegisterPreMigration(schemaVersion uint, fn customMigrationFunc) {
|
|
|
|
v := preMigrations[schemaVersion]
|
|
|
|
v = append(v, fn)
|
|
|
|
preMigrations[schemaVersion] = v
|
2021-09-21 01:48:52 +00:00
|
|
|
}
|
2022-07-13 06:30:54 +00:00
|
|
|
|
|
|
|
var postMigrations = make(map[uint][]customMigrationFunc)
|
|
|
|
var preMigrations = make(map[uint][]customMigrationFunc)
|