Skip to content

Commit 00f10c6

Browse files
author
RahatMelsov
committed
feat: добавлены пути для миграции
1 parent 637889e commit 00f10c6

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

cmd/server/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package main
22

33
import (
44
"database/sql"
5-
"log"
5+
"fmt"
66
"net"
77
"time"
88

9+
"github.com/charmbracelet/log"
910
"google.golang.org/grpc/reflection"
1011

1112
commonv1 "github.com/rtmelsov/adv-keeper/gen/go/proto/common/v1"
@@ -31,7 +32,9 @@ func main() {
3132
if err != nil {
3233
log.Fatal(err)
3334
}
34-
helpers.RunMigrations(envs.DBDSN)
35+
path := fmt.Sprintf("file:/%s", envs.MigrationsFilesDir)
36+
log.Info("path", "path", path)
37+
helpers.RunMigrations(envs.DBDSN, path)
3538
// Подключение к Postgres
3639
dbx, err := sql.Open("pgx", envs.DBDSN)
3740
if err != nil {
@@ -56,7 +59,7 @@ func main() {
5659

5760
reflection.Register(s)
5861

59-
log.Println("gRPC listening on", lis.Addr())
62+
log.Info("gRPC listening on", "add", lis.Addr())
6063
if err := s.Serve(lis); err != nil {
6164
log.Fatal(err)
6265
}

internal/helpers/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
)
99

1010
type Config struct {
11-
Addr string `env:"AK_GRPC_ADDR,required"`
12-
DBDSN string `env:"DB_DSN,required"`
13-
JWTSecret string `env:"JWT_SECRET,required" json:"-"`
14-
FilesDir string `env:"FILES_DIR" envDefault:"./files"`
15-
AccessTTL string `env:"ACCESS_TTL" envDefault:"15m"`
16-
DownloadFilesDir string `env:"DOWNLOAD_FILES_DIR" envDefault:"./opt/adv-keeper/download"`
11+
Addr string `env:"AK_GRPC_ADDR,required"`
12+
DBDSN string `env:"DB_DSN,required"`
13+
JWTSecret string `env:"JWT_SECRET,required" json:"-"`
14+
FilesDir string `env:"FILES_DIR"`
15+
AccessTTL string `env:"ACCESS_TTL"`
16+
DownloadFilesDir string `env:"DOWNLOAD_FILES_DIR"`
17+
MigrationsFilesDir string `env:"MIGRATIONS_FILES_DIR"`
1718
}
1819

1920
var (

internal/helpers/migrations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"log"
88
)
99

10-
func RunMigrations(dsn string) {
10+
func RunMigrations(dsn, filePath string) {
1111
m, err := migrate.New(
12-
"file://migrations", // путь до миграций
12+
filePath,
1313
dsn,
1414
)
1515
if err != nil {

0 commit comments

Comments
 (0)