Skip to content

Commit

Permalink
feature(): add automatic database migration
Browse files Browse the repository at this point in the history
  • Loading branch information
talDoFlemis committed Apr 25, 2024
1 parent 281a379 commit 6f8e604
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/migrate-database.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Migrate database

on:
push:
branches: ["main"]
paths: ["backend/internal/adapters/driven/postgres/migrations/**"]

defaults:
run:
working-directory: ./backend

permissions:
contents: read

jobs:
if_merged:
if: github.event.pull_request.merged == true

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22.x"
cache-dependency-path: backend/go.sum

- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Migrate database
run: task migrate
env:
BRAIN_POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
BRAIN_POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
BRAIN_POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
BRAIN_POSTGRES_DATABASE: ${{ secrets.POSTGRES_DATABASE }}
BRAIN_POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
4 changes: 4 additions & 0 deletions backend/cmd/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func main() {
if err != nil {
log.Fatal(err)
}
err = koanf.LoadFromEnv("BRAIN_")
if err != nil {
log.Fatal(err)
}
pgCfg, err := config.NewPostgresConfig()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 6f8e604

Please sign in to comment.