diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index c0c6d603..56123e25 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -17,35 +17,9 @@ jobs:
- name: run tests
run: go test -v ./...
working-directory: ./server
- test_migrations:
- runs-on: ubuntu-latest
- services:
- mariadb:
- image: bitnami/mariadb:latest
- ports:
- - 3306:3306
- env:
- MARIADB_ROOT_PASSWORD: super_secret_passw0rd
- MARIADB_DATABASE: campus_db
- steps:
- - uses: actions/checkout@v4
- - uses: actions/setup-go@v4
- with:
- go-version: '1.21'
- cache-dependency-path: |
- server/go.sum
- - name: wait for db
- run: sleep 20 && docker logs $(docker ps -qa)
- - name: run migration
- run: go run main.go
- working-directory: ./server
- env:
- CI_EXIT_AFTER_MIGRATION: "true"
- DB_DSN: root:super_secret_passw0rd@tcp(localhost:3306)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
- ENVIRONMENT: dev
build:
runs-on: ubuntu-latest
- needs: [test, test_migrations]
+ needs: [test]
steps:
- name: Checkout repository
uses: actions/checkout@v4
diff --git a/.github/workflows/test_migration.yml b/.github/workflows/test_migration.yml
new file mode 100644
index 00000000..a8b9b51b
--- /dev/null
+++ b/.github/workflows/test_migration.yml
@@ -0,0 +1,91 @@
+name: Migration Test
+on:
+ pull_request:
+ branches: [ main ]
+concurrency:
+ group: ${{ github.head_ref }}
+ cancel-in-progress: true
+jobs:
+ test_migrations:
+ runs-on: ubuntu-latest
+ services:
+ 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
+ with:
+ go-version: '1.21'
+ cache-dependency-path: |
+ server/go.sum
+ - 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
+ - uses: ariga/setup-atlas@master
+ - name: export diff the migrations
+ id: diff_migrations
+ run: |
+ EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) &&
+ echo "local_to_auto<<$EOF" >> $GITHUB_OUTPUT &&
+ atlas schema diff --from "maria://root:super_secret_passw0rd@localhost:3306/campus_db" --to "maria://root:super_secret_passw0rd@localhost:3300/campus_db" --format '{{ sql . " " }}' >> $GITHUB_OUTPUT &&
+ echo "$EOF" >> $GITHUB_OUTPUT
+ echo "auto_to_local<<$EOF" >> $GITHUB_OUTPUT &&
+ atlas schema diff --from "maria://root:super_secret_passw0rd@localhost:3306/campus_db" --to "maria://root:super_secret_passw0rd@localhost:3300/campus_db" --format '{{ sql . " " }}' >> $GITHUB_OUTPUT &&
+ echo "$EOF" >> $GITHUB_OUTPUT
+ - name: Find Comment
+ uses: peter-evans/find-comment@v2
+ id: fc
+ with:
+ issue-number: "${{ github.event.number }}"
+ body-includes: Found the following differences in the sql schema
+ comment-author: github-actions[bot]
+ - name: Create comment
+ uses: peter-evans/create-or-update-comment@v3
+ with:
+ issue-number: "${{ github.event.number }}"
+ comment-id: "${{ steps.fc.outputs.comment-id }}"
+ body: |
+ :eyes: Found the following differences in the sql schema:
+
+
+ Needed get from local to auto migration state
+
+ ```sql
+ ${{ steps.diff_migrations.outputs.local_to_auto }}
+ ```
+
+
+
+ Needed from auto to local migration state
+
+ ```sql
+ ${{ steps.diff_migrations.outputs.auto_to_local }}
+ ```
+
+
+ edit-mode: replace
diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go
index c13e32d5..2c477d31 100644
--- a/server/backend/migration/migration.go
+++ b/server/backend/migration/migration.go
@@ -12,12 +12,48 @@ import (
func autoMigrate(db *gorm.DB) error {
err := db.AutoMigrate(
+ &model.Cafeteria{},
+ &model.CafeteriaRating{},
+ &model.CafeteriaRatingAverage{},
+ &model.CafeteriaRatingTag{},
+ &model.CafeteriaRatingTagAverage{},
+ &model.CafeteriaRatingTagOption{},
+ &model.CanteenHeadCount{},
&model.Crontab{},
+ &model.Device{},
+ &model.Dish{},
+ &model.DishNameTag{},
+ &model.DishNameTagAverage{},
+ &model.DishNameTagOption{},
+ &model.DishNameTagOptionExcluded{},
+ &model.DishNameTagOptionIncluded{},
+ &model.DishRating{},
+ &model.DishRatingAverage{},
+ &model.DishRatingTag{},
+ &model.DishRatingTagAverage{},
+ &model.DishRatingTagOption{},
+ &model.DishToDishNameTag{},
+ &model.DishesOfTheWeek{},
+ &model.PublishedExamResult{},
+ &model.Feedback{},
&model.File{},
- &model.NewsSource{},
- &model.NewsAlert{},
+ &model.IOSDevice{},
+ //&model.IOSDeviceLastUpdated{}, -- not a gorm model
+ &model.IOSDeviceRequestLog{},
+ &model.IOSDevicesActivityReset{},
+ //&model.IOSGrade{}, -- not a gorm model
+ //&model.IOSRemoteNotification...{}, -- wtf???
+ &model.IOSScheduledUpdateLog{},
+ &model.IOSSchedulingPriority{},
+ &model.Kino{},
+ &model.NewExamResultsSubscriber{},
&model.News{},
- &model.CanteenHeadCount{},
+ &model.NewsAlert{},
+ &model.NewsSource{},
+ &model.Notification{},
+ &model.NotificationConfirmation{},
+ &model.NotificationType{},
+ &model.UpdateNote{},
)
return err
}
diff --git a/server/model/device.go b/server/model/device.go
index 6542aa24..52ca2707 100755
--- a/server/model/device.go
+++ b/server/model/device.go
@@ -12,14 +12,14 @@ type Device struct {
Member null.Int `gorm:"column:member;type:int;" json:"member"`
UUID string `gorm:"column:uuid;type:varchar(50);" json:"uuid"`
Created null.Time `gorm:"column:created;type:timestamp;" json:"created"`
- LastAccess time.Time `gorm:"column:lastAccess;type:timestamp;default:0000-00-00 00:00:00;" json:"last_access"`
+ LastAccess time.Time `gorm:"column:lastAccess;type:timestamp;default:'0000-00-00 00:00:00';" json:"last_access"`
LastAPI string `gorm:"column:lastApi;type:text;size:16777215;" json:"last_api"`
- Developer string `gorm:"column:developer;type:char;size:5;default:false;" json:"developer"`
+ Developer string `gorm:"column:developer;type:enum('true','false');default:'false';" json:"developer"`
OsVersion string `gorm:"column:osVersion;type:text;size:16777215;" json:"os_version"`
AppVersion string `gorm:"column:appVersion;type:text;size:16777215;" json:"app_version"`
Counter int32 `gorm:"column:counter;type:int;default:0;" json:"counter"`
Pk null.String `gorm:"column:pk;type:text;size:4294967295;" json:"pk"`
- PkActive string `gorm:"column:pkActive;type:char;size:5;default:false;" json:"pk_active"`
+ PkActive string `gorm:"column:pkActive;type:enum('true', 'false');default:'false';" json:"pk_active"`
GcmToken null.String `gorm:"column:gcmToken;type:text;size:65535;" json:"gcm_token"`
GcmStatus null.String `gorm:"column:gcmStatus;type:varchar(200);" json:"gcm_status"`
ConfirmationKey null.String `gorm:"column:confirmationKey;type:varchar(35);" json:"confirmation_key"`
diff --git a/server/model/notification_type.go b/server/model/notification_type.go
index 661383d7..7a53f240 100644
--- a/server/model/notification_type.go
+++ b/server/model/notification_type.go
@@ -19,5 +19,5 @@ var (
type NotificationType struct {
Type int64 `gorm:"primary_key;AUTO_INCREMENT;column:type;type:int;" json:"type"`
Name string `gorm:"column:name;type:text;size:65535;" json:"name"`
- Confirmation string `gorm:"column:confirmation;type:char;size:5;default:false;" json:"confirmation"`
+ Confirmation string `gorm:"column:confirmation;type:enum('true', 'false');default:'false';" json:"confirmation"`
}
diff --git a/server/utils/db.go b/server/utils/db.go
index 59d7bdb4..802852ac 100644
--- a/server/utils/db.go
+++ b/server/utils/db.go
@@ -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")
}