[SDP-1269] Add CI to validate single-tenant to multi-tenant migration #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | | |
SECONDS=0 | |
until pg_isready; do | |
echo "Waiting for postgres container... $SECONDS seconds elapsed" | |
sleep 2 | |
if [ $SECONDS -ge 8 ]; then | |
echo "Postgres container is not ready after 16 seconds." | |
exit 1 | |
fi | |
done | |
- name: Load Database Dump | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable | |
run: | | |
psql -d $DATABASE_URL -f .github/resources/single_tenant_dump.sql | |
psql -d $DATABASE_URL -c "SELECT current_database();" | |
- name: Run Go migrations | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable | |
run: | | |
psql -d $DATABASE_URL -c "SELECT current_database();" | |
go run main.go db admin migrate up --database-url=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable | |
go run main.go db tss migrate up --database-url=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable | |
- name: Start Go Server in Background | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable | |
ENABLE_SCHEDULER: "true" | |
EVENT_BROKER_TYPE: "NONE" | |
run: | | |
nohup go run main.go serve > server.log 2> server.log.err < /dev/null & | |
- name: Wait for Go Server to be ready | |
run: | | |
SECONDS=0 | |
until curl -s http://localhost:8000/health; do | |
echo "Waiting for Go server... $SECONDS seconds elapsed" | |
sleep 2 | |
if [ $SECONDS -ge 8 ]; then | |
echo "Go server is not ready after 16 seconds." | |
exit 1 | |
fi | |
done | |
- name: execute curl to create tenant | |
run: | | |
adminAccount="SDP-admin" | |
adminApiKey="api_key_1234567890" | |
encodedCredentials=$(echo -n "$adminAccount:$adminApiKey" | base64) | |
AuthHeader="Authorization: Basic $encodedCredentials" | |
curl -X POST http://localhost:8003/tenants -H "$AuthHeader" -d '{ | |
"name": "migrated-tenant", | |
"organization_name": "migrated-tenant", | |
"owner_email": "init_owner@$tenant.local", | |
"owner_first_name": "jane", | |
"owner_last_name": "doe", | |
"distribution_account_type": "DISTRIBUTION_ACCOUNT.STELLAR.DB_VAULT" | |
}' | |
- name: Execute migration function | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable | |
run: | | |
psql -d $DATABASE_URL -c "SELECT current_database();" | |
psql -d $DATABASE_URL -c "SHOW search_path;" | |
psql -d $DATABASE_URL -c "SELECT schema_name FROM information_schema.schemata;" | |
psql -d $DATABASE_URL -c "SELECT admin.migrate_tenant_data_from_v1_to_v2('migrated-tenant');" | |
- name: Execute cleanup queries | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable | |
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;" | |
- name: Print server.log content | |
if: always() | |
run: | | |
pwd | |
ls -la | |
if [ -f server.log ]; then | |
cat server.log | |
else | |
echo "server.log does not exist." | |
fi | |
if [ -f server.log.err ]; then | |
cat server.log.err | |
else | |
echo "server.log.err does not exist." | |
fi |