Skip to content

Commit

Permalink
enabled the auto migration in the workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Oct 22, 2023
1 parent 8ef8eda commit 0a189ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ jobs:
test_migrations:
runs-on: ubuntu-latest
services:
mariadb:
auto_mariadb:
image: bitnami/mariadb:latest
ports:
- 3306:3306
env:
MARIADB_ROOT_PASSWORD: super_secret_passw0rd
MARIADB_DATABASE: campus_db
manual_mariadb:
image: bitnami/mariadb:latest
ports:
- 3300:3306
env:
MARIADB_ROOT_PASSWORD: super_secret_passw0rd
MARIADB_DATABASE: campus_db
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
Expand All @@ -35,14 +42,23 @@ jobs:
cache-dependency-path: |
server/go.sum
- name: wait for db
run: sleep 20 && docker logs $(docker ps -qa)
- name: run migration
run: sleep 20
- name: run manual migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "false"
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3306)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- name: run auto migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "true"
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3300)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
build:
runs-on: ubuntu-latest
needs: [test, test_migrations]
Expand Down
2 changes: 1 addition & 1 deletion server/utils/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func SetupDB() *gorm.DB {

// Migrate the schema
// currently not activated as
if err := migration.Migrate(db, false); err != nil {
if err := migration.Migrate(db, os.Getenv("CI_AUTO_MIGRATION") == "true"); err != nil {
log.WithError(err).Fatal("Failed to migrate database")
}

Expand Down

0 comments on commit 0a189ee

Please sign in to comment.