mirror of
https://github.com/yanislav-igonin/micrach
synced 2025-07-01 17:01:14 +03:00
wip
This commit is contained in:
parent
39b93514a8
commit
f812166fc8
12
db/db.go
12
db/db.go
@ -3,8 +3,11 @@ package db
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
Config "micrach/config"
|
||||
Files "micrach/files"
|
||||
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
)
|
||||
@ -23,5 +26,14 @@ func Init() {
|
||||
}
|
||||
|
||||
func Migrate() {
|
||||
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))
|
||||
}
|
||||
log.Println("database migrations - online")
|
||||
}
|
||||
|
@ -4,25 +4,37 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"path"
|
||||
)
|
||||
|
||||
func GetFilesInFolder(folder string) []string {
|
||||
// Reads folder and returns full file paths slice
|
||||
func GetFullFilePathsInFolder(folder string) []string {
|
||||
currentPath, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(filepath.Join(currentPath + "/migrations"))
|
||||
fullFolderPath := path.Join(currentPath, folder)
|
||||
files, err := ioutil.ReadDir(fullFolderPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var filesNames []string
|
||||
var paths []string
|
||||
|
||||
for _, file := range files {
|
||||
filesNames = append(filesNames, file.Name())
|
||||
paths = append(paths, path.Join(fullFolderPath, file.Name()))
|
||||
}
|
||||
|
||||
return filesNames
|
||||
return paths
|
||||
}
|
||||
|
||||
// Reads file contents by full path and returns string
|
||||
func ReadFileText(fullFilePath string) string {
|
||||
file, err := ioutil.ReadFile(fullFilePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return string(file)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user