From 39dd9ac14625b9c7f9d896e23bf5c4a24032c87f Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 16:38:01 -0800 Subject: [PATCH 1/8] chore: test case: should not run for no migration Signed-off-by: Matt Krick --- .github/workflows/migration-order.yml | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/migration-order.yml diff --git a/.github/workflows/migration-order.yml b/.github/workflows/migration-order.yml new file mode 100644 index 00000000000..c445b12c0eb --- /dev/null +++ b/.github/workflows/migration-order.yml @@ -0,0 +1,39 @@ +name: Migration Order +on: + pull_request: + paths: + - packages/server/postgres/migrations/*.ts +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + migration-order: + runs-on: ubuntu-latest + steps: + - name: Checkout master + uses: actions/checkout@v3 + with: + ref: master + + - name: Get newest migration on master + run: | + MAX_OLD_MIGRATION=$(ls packages/server/postgres/migrations | tail -n 1) + echo MAX_OLD_MIGRATION=$MAX_OLD_MIGRATION >> $GITHUB_ENV + + - name: Checkout PR + uses: actions/checkout@v3 + + - name: Get new migrations + id: new-migrations + uses: tj-actions/changed-files@v40 + with: + files: packages/server/postgres/migrations/*.ts + + - name: Check migration conflicts + run: | + for file in ${{ steps.new-migrations.outputs.added_files }}; do + if [[ "$file" < "${{ env.MAX_OLD_MIGRATION }}" ]]; then + echo "Migration $file predates ${{ env.MAX_OLD_MIGRATION}}. Please rename it" + exit 1 + fi + done From cd7c561c88075a2f57f43daff79624daefd71a78 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 16:40:12 -0800 Subject: [PATCH 2/8] test: working case Signed-off-by: Matt Krick --- .../postgres/migrations/1699576803835_fooyeah.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 packages/server/postgres/migrations/1699576803835_fooyeah.ts diff --git a/packages/server/postgres/migrations/1699576803835_fooyeah.ts b/packages/server/postgres/migrations/1699576803835_fooyeah.ts new file mode 100644 index 00000000000..feb386cfdce --- /dev/null +++ b/packages/server/postgres/migrations/1699576803835_fooyeah.ts @@ -0,0 +1,16 @@ +import {Client} from 'pg' +import getPgConfig from '../getPgConfig' + +export async function up() { + const client = new Client(getPgConfig()) + await client.connect() + await client.query(`` /* Do good magic */) + await client.end() +} + +export async function down() { + const client = new Client(getPgConfig()) + await client.connect() + await client.query(`` /* Do undo magic */) + await client.end() +} From 25ad89fee4f22efead30f3a45d11d3a83590552b Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 16:43:03 -0800 Subject: [PATCH 3/8] test: failing case Signed-off-by: Matt Krick --- .github/workflows/migration-order.yml | 6 ++++-- .../{1699576803835_fooyeah.ts => 1697576803835_fooyeah.ts} | 0 2 files changed, 4 insertions(+), 2 deletions(-) rename packages/server/postgres/migrations/{1699576803835_fooyeah.ts => 1697576803835_fooyeah.ts} (100%) diff --git a/.github/workflows/migration-order.yml b/.github/workflows/migration-order.yml index c445b12c0eb..e7323989a84 100644 --- a/.github/workflows/migration-order.yml +++ b/.github/workflows/migration-order.yml @@ -33,7 +33,9 @@ jobs: run: | for file in ${{ steps.new-migrations.outputs.added_files }}; do if [[ "$file" < "${{ env.MAX_OLD_MIGRATION }}" ]]; then - echo "Migration $file predates ${{ env.MAX_OLD_MIGRATION}}. Please rename it" - exit 1 + echo "Migration $file predates ${{ env.MAX_OLD_MIGRATION}}. Please rename it" + exit 1 + el + echo "Migration $file does not conflict with existing migrations on master" fi done diff --git a/packages/server/postgres/migrations/1699576803835_fooyeah.ts b/packages/server/postgres/migrations/1697576803835_fooyeah.ts similarity index 100% rename from packages/server/postgres/migrations/1699576803835_fooyeah.ts rename to packages/server/postgres/migrations/1697576803835_fooyeah.ts From e1c631d268a9a33dba9c252f33ce7c21f66e8cf4 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 16:46:21 -0800 Subject: [PATCH 4/8] debug failing case --- .github/workflows/migration-order.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/migration-order.yml b/.github/workflows/migration-order.yml index e7323989a84..313b94309b5 100644 --- a/.github/workflows/migration-order.yml +++ b/.github/workflows/migration-order.yml @@ -32,10 +32,11 @@ jobs: - name: Check migration conflicts run: | for file in ${{ steps.new-migrations.outputs.added_files }}; do + echo "Testing $file" if [[ "$file" < "${{ env.MAX_OLD_MIGRATION }}" ]]; then echo "Migration $file predates ${{ env.MAX_OLD_MIGRATION}}. Please rename it" exit 1 - el + else echo "Migration $file does not conflict with existing migrations on master" fi done From f2d324c8c2adb2357d30751fe89b4bd0881ed258 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 16:54:18 -0800 Subject: [PATCH 5/8] test basename Signed-off-by: Matt Krick --- .github/workflows/migration-order.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/migration-order.yml b/.github/workflows/migration-order.yml index 313b94309b5..b6151101f7d 100644 --- a/.github/workflows/migration-order.yml +++ b/.github/workflows/migration-order.yml @@ -33,7 +33,7 @@ jobs: run: | for file in ${{ steps.new-migrations.outputs.added_files }}; do echo "Testing $file" - if [[ "$file" < "${{ env.MAX_OLD_MIGRATION }}" ]]; then + if [[ "$(basename $file)" < "${{ env.MAX_OLD_MIGRATION }}" ]]; then echo "Migration $file predates ${{ env.MAX_OLD_MIGRATION}}. Please rename it" exit 1 else From c4ea5b16a9e02a7d941652772fdbf5e4c6395351 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 16:55:33 -0800 Subject: [PATCH 6/8] test working case --- .../{1697576803835_fooyeah.ts => 1699576803835_fooyeah.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/server/postgres/migrations/{1697576803835_fooyeah.ts => 1699576803835_fooyeah.ts} (100%) diff --git a/packages/server/postgres/migrations/1697576803835_fooyeah.ts b/packages/server/postgres/migrations/1699576803835_fooyeah.ts similarity index 100% rename from packages/server/postgres/migrations/1697576803835_fooyeah.ts rename to packages/server/postgres/migrations/1699576803835_fooyeah.ts From 1f663dab27bf44f1242d9d10a3548405c7ed63dc Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 16:58:24 -0800 Subject: [PATCH 7/8] better logs Signed-off-by: Matt Krick --- .github/workflows/migration-order.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/migration-order.yml b/.github/workflows/migration-order.yml index b6151101f7d..196a45066ad 100644 --- a/.github/workflows/migration-order.yml +++ b/.github/workflows/migration-order.yml @@ -32,11 +32,11 @@ jobs: - name: Check migration conflicts run: | for file in ${{ steps.new-migrations.outputs.added_files }}; do - echo "Testing $file" - if [[ "$(basename $file)" < "${{ env.MAX_OLD_MIGRATION }}" ]]; then - echo "Migration $file predates ${{ env.MAX_OLD_MIGRATION}}. Please rename it" + FILE_NAME=$(basename $file) + if [[ "$FILE_NAME" < "${{ env.MAX_OLD_MIGRATION }}" ]]; then + echo "$FILE_NAME predates ${{ env.MAX_OLD_MIGRATION}}. Please rename it" exit 1 else - echo "Migration $file does not conflict with existing migrations on master" + echo "$FILE_NAME does not conflict with existing migrations on master" fi done From 303d3b30dd9c380b1d3660e65bfc1d4e660e9896 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 16:59:27 -0800 Subject: [PATCH 8/8] test no migration Signed-off-by: Matt Krick --- .github/workflows/migration-order.yml | 3 --- .../postgres/migrations/1699576803835_fooyeah.ts | 16 ---------------- 2 files changed, 19 deletions(-) delete mode 100644 packages/server/postgres/migrations/1699576803835_fooyeah.ts diff --git a/.github/workflows/migration-order.yml b/.github/workflows/migration-order.yml index 196a45066ad..2f350718837 100644 --- a/.github/workflows/migration-order.yml +++ b/.github/workflows/migration-order.yml @@ -3,9 +3,6 @@ on: pull_request: paths: - packages/server/postgres/migrations/*.ts -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true jobs: migration-order: runs-on: ubuntu-latest diff --git a/packages/server/postgres/migrations/1699576803835_fooyeah.ts b/packages/server/postgres/migrations/1699576803835_fooyeah.ts deleted file mode 100644 index feb386cfdce..00000000000 --- a/packages/server/postgres/migrations/1699576803835_fooyeah.ts +++ /dev/null @@ -1,16 +0,0 @@ -import {Client} from 'pg' -import getPgConfig from '../getPgConfig' - -export async function up() { - const client = new Client(getPgConfig()) - await client.connect() - await client.query(`` /* Do good magic */) - await client.end() -} - -export async function down() { - const client = new Client(getPgConfig()) - await client.connect() - await client.query(`` /* Do undo magic */) - await client.end() -}