mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
feat: little refactoring
This commit is contained in:
parent
62be228308
commit
cb4eaa9fc2
25
db/db.go
25
db/db.go
@ -47,16 +47,8 @@ func Migrate() {
|
||||
|
||||
_, isMigrationInDb := dbMigrations[id]
|
||||
if !isMigrationInDb {
|
||||
_, err := Pool.Exec(context.TODO(), Files.ReadFileText(m))
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
sql := `INSERT INTO migrations (id, name) VALUES ($1, $2)`
|
||||
_, err = Pool.Query(context.TODO(), sql, id, name)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
sql := Files.ReadFileText(m)
|
||||
runMigration(id, name, sql)
|
||||
log.Println("database migration - " + name + " - online")
|
||||
}
|
||||
}
|
||||
@ -64,6 +56,19 @@ func Migrate() {
|
||||
log.Println("database migrations - online")
|
||||
}
|
||||
|
||||
func runMigration(mid int, mname, msql string) {
|
||||
_, err := Pool.Exec(context.TODO(), msql)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
sql := `INSERT INTO migrations (id, name) VALUES ($1, $2)`
|
||||
_, err = Pool.Query(context.TODO(), sql, mid, mname)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getDbMigrations() MigrationsMap {
|
||||
sql := `SELECT id, name FROM migrations`
|
||||
rows, err := Pool.Query(context.TODO(), sql)
|
||||
|
Loading…
Reference in New Issue
Block a user