2021-08-26 16:16:50 +03:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
2021-11-14 13:14:10 +03:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2021-08-26 16:16:50 +03:00
|
|
|
|
|
|
|
Config "micrach/config"
|
2021-11-14 13:14:10 +03:00
|
|
|
Files "micrach/files"
|
2021-08-26 16:16:50 +03:00
|
|
|
|
|
|
|
"github.com/jackc/pgx/v4/pgxpool"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Pool *pgxpool.Pool
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
var err error
|
2021-09-10 19:16:53 +03:00
|
|
|
Pool, err = pgxpool.Connect(context.TODO(), Config.Db.Url)
|
2021-08-26 16:16:50 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Println("database - offline")
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("database - online")
|
|
|
|
}
|
2021-11-07 11:42:54 +03:00
|
|
|
|
|
|
|
func Migrate() {
|
2021-11-14 13:14:10 +03:00
|
|
|
migrations := Files.GetFullFilePathsInFolder("migrations")
|
|
|
|
log.Println(migrations)
|
|
|
|
for _, m := range migrations {
|
|
|
|
filename := filepath.Base(m)
|
|
|
|
splitted := strings.Split(filename, "-")
|
|
|
|
id, name := splitted[0], splitted[1]
|
|
|
|
log.Println(id, name)
|
|
|
|
log.Println(Files.ReadFileText(m))
|
|
|
|
}
|
2021-11-07 11:42:54 +03:00
|
|
|
log.Println("database migrations - online")
|
|
|
|
}
|