Skip to content

Commit

Permalink
Merge pull request #146 from GMOD/145-testing-flyway-with-tripal
Browse files Browse the repository at this point in the history
Automated testing for applying migrations in a named schema
  • Loading branch information
laceysanderson authored May 27, 2024
2 parents e08d2f7 + e72a2f9 commit 5858a73
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Testing Flyway Migrations
name: "Testing Flyway Migrations: Public Schema"
on:
workflow_dispatch:
pull_request:
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/ALL-testMigrateTripal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Testing Flyway Migrations: Named Schema Teacup"
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize]

jobs:
run-tests:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
pgsql-version:
- "12"
- "13"
- "14"
- "15"
- "16"
steps:
# Check out the repo
- name: Checkout Repository
uses: actions/checkout@v4
# Here we fully build a docker using the current checked out code
# to ensure we test the current migrations.
- name: Build Docker Image
run: |
docker build --tag gmod/chado:local \
--file docker/Dockerfile \
--build-arg PGSQL_VERSION="${{ matrix.pgsql-version }}" \
--build-arg SCHEMA_NAME="teacup" \
--build-arg APPLY_MIGRATIONS=0 ./
# Just spin up docker the good ol' fashion way
# then run flyway baseline and migrate.
- name: Run Flyway Migrate
run: |
docker run --name=chadodocker -tid gmod/chado:local
sleep 30
docker exec chadodocker flyway migrate
12 changes: 11 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM ubuntu:24.04
ARG CHADO_VERSION='1.31'
ARG PGSQL_VERSION='16'
ARG APPLY_MIGRATIONS='0'
ARG SCHEMA_NAME='public'

RUN apt-get update

Expand Down Expand Up @@ -39,12 +40,21 @@ RUN cp flyway.toml /root/flyway.toml \
&& chmod +x /usr/bin/entrypoint.sh \
&& cp motd /etc/motd

RUN if [ "$SCHEMA_NAME" != "public" ] ; then \
/etc/init.d/postgresql start \
&& sleep 30 \
&& su -c "psql -d chado -c \"ALTER SCHEMA public RENAME TO $SCHEMA_NAME; CREATE SCHEMA public;\"" - postgres \
&& sed -i "s/public/$SCHEMA_NAME/g" /root/flyway.toml \
&& /etc/init.d/postgresql stop; \
fi

RUN /etc/init.d/postgresql start \
&& sleep 30 \
&& flyway baseline \
&& if [ "$APPLY_MIGRATIONS" = "1" ] ; then \
flyway migrate; \
fi
fi \
&& /etc/init.d/postgresql stop

WORKDIR /Chado

Expand Down

0 comments on commit 5858a73

Please sign in to comment.