From d45be3fe6684adc69f2fd0cfb276ca1f84ced5ba Mon Sep 17 00:00:00 2001 From: Theo Sanderson Date: Sat, 3 Aug 2024 00:48:12 +0100 Subject: [PATCH] Ensure flyway migrations are not changed (and validate them) --- .github/workflows/flyway-check.yml | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/flyway-check.yml 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