From e3f7c263b092ffb80b966979ce64248aa487016b Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Wed, 15 Sep 2021 08:26:39 -0400 Subject: [PATCH] refactor(sqltest): Update init script to support migration editions This updates the docker image used for tests to support the new location for sql migration files and the concept of editions. It continues to process the old paths for now if the new directory does not exist, so that the same image can be used during the transition. --- internal/db/sqltest/Makefile | 4 +-- internal/db/sqltest/initdb.d/00_schema.sh | 33 +++++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/internal/db/sqltest/Makefile b/internal/db/sqltest/Makefile index 5305a6bb4e..04731bb218 100644 --- a/internal/db/sqltest/Makefile +++ b/internal/db/sqltest/Makefile @@ -33,7 +33,7 @@ test: -e POSTGRES_PASSWORD=boundary \ -e POSTGRES_USER=boundary \ -e POSTGRES_DB=boundary \ - -v "$(CWD)/../schema/migrations/postgres":/migrations \ + -v "$(CWD)/../schema/migrations":/migrations \ -v "$(CWD)/initdb.d":/docker-entrypoint-initdb.d/ \ $(POSTGRES_DOCKER_IMAGE) @docker run -it --rm \ @@ -56,7 +56,7 @@ database-up: -e POSTGRES_PASSWORD=boundary \ -e POSTGRES_USER=boundary \ -e POSTGRES_DB=boundary \ - -v "$(CWD)/../schema/migrations/postgres":/migrations \ + -v "$(CWD)/../schema/migrations":/migrations \ -v "$(CWD)/initdb.d":/docker-entrypoint-initdb.d/ \ $(POSTGRES_DOCKER_IMAGE) diff --git a/internal/db/sqltest/initdb.d/00_schema.sh b/internal/db/sqltest/initdb.d/00_schema.sh index b1cc3fdb7a..a2ce2aa0ba 100755 --- a/internal/db/sqltest/initdb.d/00_schema.sh +++ b/internal/db/sqltest/initdb.d/00_schema.sh @@ -26,8 +26,31 @@ docker_process_sql() { PGHOST= PGHOSTADDR= "${query_runner[@]}" "$@" } -# Run migrations in order. -for file in $(ls -v /migrations/**/*.sql); do - echo running "$file" - docker_process_sql -f "$file" -done +if [ -d /migrations/base ]; then + # Run migrations in order. + for file in $(ls -v /migrations/base/postgres/**/*.up.sql); do + echo running "$file" + docker_process_sql -f "$file" + done + + if [ -d /migrations/oss ]; then + # Run migrations in order. + for file in $(ls -v /migrations/oss/postgres/**/*.up.sql); do + echo running "$file" + docker_process_sql -f "$file" + done + fi + + for d in $(find /migrations/ -mindepth 1 -maxdepth 1 -type d -not -name 'oss' -not -name 'base'); do + for file in $(ls -v ${d}/postgres/**/*.up.sql); do + echo running "$file" + docker_process_sql -f "$file" + done + done +else + # Run migrations in order. + for file in $(ls -v /migrations/**/*.up.sql); do + echo running "$file" + docker_process_sql -f "$file" + done +fi