diff --git a/.github/workflows/docker-publish-key-manager.yml b/.github/workflows/docker-publish-key-manager.yml index d9ebde5..603245a 100644 --- a/.github/workflows/docker-publish-key-manager.yml +++ b/.github/workflows/docker-publish-key-manager.yml @@ -12,6 +12,7 @@ on: tags: [ 'v*.*.*' ] paths: - 'src/key_management/**' + - 'src/cmd/**' - 'src/middleware/**' - 'src/model/**' - 'src/util/**' @@ -20,6 +21,7 @@ on: branches: [ "main" ] paths: - 'src/key_management/**' + - 'src/cmd/**' - 'src/middleware/**' - 'src/model/**' - 'src/util/**' @@ -31,6 +33,7 @@ env: # github.repository as / IMAGE_NAME: ${{ github.repository }} KEY_MAN_DIR: "src/key_management" + SRC_DIR: "src" AWS_REGION: us-east-1 ECS_SERVICE: holidays-key-manager-service ECS_CLUSTER: holidays-cluster @@ -109,7 +112,7 @@ jobs: runs-on: ubuntu-latest services: postgres: - image: postgres:16 + image: postgres:17 env: POSTGRES_USER: app POSTGRES_PASSWORD: password @@ -128,11 +131,11 @@ jobs: src/go.sum - name: Run migration - working-directory: ${{ env.KEY_MAN_DIR }} + working-directory: ${{ env.SRC_DIR }} shell: bash -l {0} run: | - go install github.com/pressly/goose/v3/cmd/goose@latest - $(go env GOPATH)/bin/goose --dir database/migrations/ postgres "host=localhost user=app password=password dbname=unittest sslmode=disable" up + go mod download + go run src/cmd/migration.go - name: Build working-directory: ${{ env.KEY_MAN_DIR }} diff --git a/src/cmd/migration.go b/src/cmd/migration.go new file mode 100644 index 0000000..c2af036 --- /dev/null +++ b/src/cmd/migration.go @@ -0,0 +1,31 @@ +package main + +import ( + "github.com/kynmh69/go-ja-holidays/database" + "github.com/kynmh69/go-ja-holidays/logging" + "github.com/kynmh69/go-ja-holidays/model" +) + +func init() { + // logger initialize + logging.LoggerInitialize() + // connect database + database.ConnectDatabase() +} + +func main() { + // get logger + logger := logging.GetLogger() + // migration db + db := database.GetDbConnection() + // migrate db + if err := db.AutoMigrate( + &model.ApiKey{}, + &model.HolidayData{}, + ); err != nil { + // if failed to migrate db, panic + logger.Panicln("failed to migrate db", err) + } + // if success to migrate db, log + logger.Infoln("migrate db success") +}