Skip to content

Commit

Permalink
feature(#20): add migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
talDoFlemis committed Apr 17, 2024
1 parent b0456e5 commit 2d90679
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions backend/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ tasks:
desc: "Check for code common vulnerabilities"
cmds:
- govulncheck ./...

migrate:
desc: "Migrate postgres"
cmds:
- go run ./cmd/migrate/
25 changes: 25 additions & 0 deletions backend/cmd/migrate/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"log"

"github.com/taldoflemis/brain.test/config"
"github.com/taldoflemis/brain.test/internal/adapters/driven/postgres"
)

func main() {
koanf := config.NewKoanfson()
err := koanf.LoadFromJSON("config.json")
if err != nil {
log.Fatal(err)
}
pgCfg, err := config.NewPostgresConfig()
if err != nil {
log.Fatal(err)
}
log.Print(pgCfg.Database)

connStr := postgres.GenerateConnectionString(pgCfg)
log.Print(connStr)
postgres.Migrate(connStr, "internal/adapters/driven/postgres/migrations/")
}
4 changes: 2 additions & 2 deletions backend/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"postgres": {
"host": "localhost",
"port": 5432,
"user": "postgres",
"user": "adminson",
"password": "password",
"database": "postgres"
"database": "brain"
}
}

0 comments on commit 2d90679

Please sign in to comment.