diff --git a/.github/workflows/flyway-check.yml b/.github/workflows/flyway-check.yml new file mode 100644 index 000000000..946632236 --- /dev/null +++ b/.github/workflows/flyway-check.yml @@ -0,0 +1,45 @@ +name: Flyway Migration Check + +on: + pull_request: + branches: [ main ] + paths: + - 'src/main/resources/db/migration/**' + +jobs: + check-migrations: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + + - name: Install Flyway CLI + run: | + wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/8.5.13/flyway-commandline-8.5.13-linux-x64.tar.gz | tar xvz + sudo ln -s `pwd`/flyway-8.5.13/flyway /usr/local/bin + + - name: Check for modified migrations + run: | + git diff --name-only origin/main...HEAD -- backend/src/main/resources/db/migration/ > changed_files.txt + if [ -s changed_files.txt ]; then + echo "The following migration files have been modified:" + cat changed_files.txt + echo "Error: Modifying existing migrations is not allowed." + exit 1 + else + echo "No existing migrations have been modified." + fi + + - name: Validate new migrations + run: flyway validate -locations=filesystem:backend/src/main/resources/db/migration + + - name: Run Flyway info + run: flyway info -locations=filesystem:backend/src/main/resources/db/migration