From a5908dd86f02f67b4038631177ae8f6ceab3512e Mon Sep 17 00:00:00 2001 From: Marcelo Salloum Date: Thu, 18 Jul 2024 12:03:48 -0700 Subject: [PATCH] Add script to check singletenant to mtn migration. --- .../singletenant-to-multitenant-migration.yml | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/singletenant-to-multitenant-migration.yml diff --git a/.github/workflows/singletenant-to-multitenant-migration.yml b/.github/workflows/singletenant-to-multitenant-migration.yml new file mode 100644 index 000000000..368d8392c --- /dev/null +++ b/.github/workflows/singletenant-to-multitenant-migration.yml @@ -0,0 +1,92 @@ +name: Singletenant to Multitenant Migration + +on: + push: + branches: + - main + - develop + + pull_request: # TODO: remove this trigger before merging the PR + +jobs: + check: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:12-alpine + env: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + PGHOST: localhost + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + env: + PGHOST: localhost + PGPORT: 5432 + PGUSER: postgres + PGPASSWORD: postgres + PGDATABASE: postgres + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.22.1 + cache: true + cache-dependency-path: go.sum + + - name: Install PostgreSQL Client + run: sudo apt-get update && sudo apt-get install -y postgresql-client + + - name: Wait for PostgreSQL to be ready + run: | + until pg_isready; do + echo "Waiting for postgres container..." + sleep 2 + done + + - name: Load Database Dump + run: psql -d $DATABASE_URL -f .github/resources/single_tenant_dump.sql + + - name: Run Go migrations + run: | + go run main.go db admin migrate up + go run main.go db tss migrate up + + - name: Execute migration function + run: | + psql -d ${DATABASE_URL} -c "SELECT admin.migrate_tenant_data_from_v1_to_v2('migrated_tenant');" + + - name: Execute cleanup queries + run: | + psql -d ${DATABASE_URL} -c " + BEGIN TRANSACTION; + DROP TABLE public.messages CASCADE; + DROP TABLE public.payments CASCADE; + DROP TABLE public.disbursements CASCADE; + DROP TABLE public.receiver_verifications CASCADE; + DROP TABLE public.receiver_wallets CASCADE; + DROP TABLE public.auth_user_password_reset CASCADE; + DROP TABLE public.auth_user_mfa_codes CASCADE; + DROP TABLE public.receivers CASCADE; + DROP TABLE public.auth_users CASCADE; + DROP TABLE public.wallets_assets CASCADE; + DROP TABLE public.assets CASCADE; + DROP TABLE public.wallets CASCADE; + DROP TABLE public.organizations CASCADE; + DROP TABLE public.gorp_migrations CASCADE; + DROP TABLE public.auth_migrations CASCADE; + DROP TABLE public.countries CASCADE; + DROP TABLE public.submitter_transactions CASCADE; + DROP TABLE public.channel_accounts CASCADE; + COMMIT;"