Add intial database migrations
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"log"
|
||||
)
|
||||
|
||||
func CheckError(e error) {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
func Update(db *sql.DB, migrations []string) {
|
||||
for _, x := range migrations {
|
||||
data, err := os.ReadFile("./db/migrations/" + x + ".sql")
|
||||
CheckError(err)
|
||||
res, err := db.Exec(string(data))
|
||||
_ = res
|
||||
CheckError(err)
|
||||
log.Print("Applied migration " + x)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user