-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDP-1269] Add CI to validate single-tenant to multi-tenant migration #356
Merged
marcelosalloum
merged 9 commits into
develop
from
marcelo/SDP-1269-CI-singletenant-to-multitenant-check
Jul 23, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
237eca5
Add dump from a singletenant instance.
marcelosalloum 699be7c
Disable other CIs while we test if the new one is working as expected
marcelosalloum 0d5946f
Small tweak.
marcelosalloum 143d561
Move dump into another folder.
marcelosalloum a001039
Add a script to test the migration.
marcelosalloum 20e4c8c
Add single-tenant to multi-tenant workflow.
marcelosalloum 283ef1c
Add an extra step to validate the row count on some tables.
marcelosalloum 41439b7
Revert "Disable other CIs while we test if the new one is working as …
marcelosalloum 799c7a8
Remove workflow_call
marcelosalloum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
.github/workflows/singletenant_to_multitenant_db_migration_test.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
name: Single-tenant to Multi-tenant | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
- "release/**" | ||
- "releases/**" | ||
- "hotfix/**" | ||
pull_request: | ||
|
||
env: | ||
USER_EMAIL: "[email protected]" | ||
USER_PASSWORD: "mockPassword123!" | ||
DATABASE_URL: "postgres://postgres@db:5432/e2e-sdp?sslmode=disable" | ||
DISTRIBUTION_ACCOUNT_TYPE: "DISTRIBUTION_ACCOUNT.STELLAR.ENV" | ||
DISTRIBUTION_PUBLIC_KEY: ${{ vars.DISTRIBUTION_PUBLIC_KEY }} | ||
DISTRIBUTION_SEED: ${{ vars.DISTRIBUTION_SEED }} | ||
CHANNEL_ACCOUNT_ENCRYPTION_PASSPHRASE: ${{ vars.DISTRIBUTION_SEED }} | ||
SEP10_SIGNING_PUBLIC_KEY: ${{ vars.SEP10_SIGNING_PUBLIC_KEY }} | ||
SEP10_SIGNING_PRIVATE_KEY: ${{ vars.SEP10_SIGNING_PRIVATE_KEY }} | ||
|
||
jobs: | ||
db-migration: | ||
runs-on: ubuntu-latest | ||
environment: "Receiver Registration - E2E Integration Tests (Stellar)" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Cleanup data | ||
working-directory: internal/integrationtests/docker | ||
run: docker-compose -f docker-compose-e2e-tests.yml down -v | ||
shell: bash | ||
|
||
- name: Run Docker Compose for SDP, Anchor Platform and TSS | ||
working-directory: internal/integrationtests/docker | ||
run: docker-compose -f docker-compose-e2e-tests.yml up --build -V -d | ||
shell: bash | ||
|
||
- name: Install curl | ||
run: sudo apt-get update && sudo apt-get install -y curl | ||
shell: bash | ||
|
||
- name: Copy DB Dump to Container and Restore | ||
run: | | ||
docker cp internal/integrationtests/resources/single_tenant_dump.sql e2e-sdp-v2-database:/tmp/single_tenant_dump.sql | ||
docker exec e2e-sdp-v2-database bash -c "psql -d $DATABASE_URL -f /tmp/single_tenant_dump.sql" | ||
|
||
- name: Provision New Tenant | ||
run: | | ||
adminAccount="SDP-admin" | ||
adminApiKey="api_key_1234567890" | ||
encodedCredentials=$(echo -n "$adminAccount:$adminApiKey" | base64) | ||
AuthHeader="Authorization: Basic $encodedCredentials" | ||
tenant="migrated-tenant" | ||
baseURL="http://$tenant.stellar.local:8000" | ||
sdpUIBaseURL="http://$tenant.stellar.local:3000" | ||
ownerEmail="init_owner@$tenant.local" | ||
AdminTenantURL="http://localhost:8003/tenants" | ||
response=$(curl -s -w "\n%{http_code}" -X POST $AdminTenantURL \ | ||
-H "Content-Type: application/json" \ | ||
-H "$AuthHeader" \ | ||
-d '{ | ||
"name": "'"$tenant"'", | ||
"organization_name": "'"$tenant"'", | ||
"base_url": "'"$baseURL"'", | ||
"sdp_ui_base_url": "'"$sdpUIBaseURL"'", | ||
"owner_email": "'"$ownerEmail"'", | ||
"owner_first_name": "jane", | ||
"owner_last_name": "doe", | ||
"distribution_account_type": "DISTRIBUTION_ACCOUNT.STELLAR.DB_VAULT" | ||
}') | ||
|
||
http_code=$(echo "$response" | tail -n1) | ||
response_body=$(echo "$response" | sed '$d') | ||
|
||
if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then | ||
echo "✅ Tenant $tenant created successfully." | ||
echo "🔗 You can now reset the password for the owner $ownerEmail on $sdpUIBaseURL/forgot-password" | ||
echo "Response body: $response_body" | ||
else | ||
echo "❌ Failed to create tenant $tenant. HTTP status code: $http_code" | ||
echo "Server response: $response_body" | ||
exit 1 | ||
fi | ||
|
||
- name: Run Migration | ||
run: | | ||
docker exec e2e-sdp-v2-database bash -c "psql -d $DATABASE_URL -c \"SELECT admin.migrate_tenant_data_from_v1_to_v2('migrated-tenant');\"" | ||
|
||
- name: Verify Row Counts | ||
run: | | ||
submitter_public_count=$(docker exec e2e-sdp-v2-database bash -c "psql -d $DATABASE_URL -t -c 'SELECT COUNT(*) FROM public.submitter_transactions;'") | ||
submitter_tss_count=$(docker exec e2e-sdp-v2-database bash -c "psql -d $DATABASE_URL -t -c 'SELECT COUNT(*) FROM tss.submitter_transactions;'") | ||
receiver_public_count=$(docker exec e2e-sdp-v2-database bash -c "psql -d $DATABASE_URL -t -c 'SELECT COUNT(*) FROM public.receivers;'") | ||
receiver_migrated_count=$(docker exec e2e-sdp-v2-database bash -c "psql -d $DATABASE_URL -t -c 'SELECT COUNT(*) FROM \"sdp_migrated-tenant\".receivers;'") | ||
|
||
if [ "$submitter_public_count" -eq "$submitter_tss_count" ] && [ "$submitter_public_count" -gt 0 ]; then | ||
echo "✅ submitter_transactions row counts match and are greater than zero." | ||
else | ||
echo "❌ submitter_transactions row counts do not match or are not greater than zero." | ||
exit 1 | ||
fi | ||
|
||
if [ "$receiver_public_count" -eq "$receiver_migrated_count" ] && [ "$receiver_public_count" -gt 0 ]; then | ||
echo "✅ receivers row counts match and are greater than zero." | ||
else | ||
echo "❌ receivers row counts do not match or are not greater than zero." | ||
exit 1 | ||
fi | ||
|
||
- name: Exclude Deprecated Tables | ||
run: | | ||
docker exec e2e-sdp-v2-database bash -c "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: Docker logs | ||
if: always() | ||
working-directory: internal/integrationtests/docker | ||
run: | | ||
docker-compose -f docker-compose-e2e-tests.yml logs | ||
docker-compose -f docker-compose-e2e-tests.yml down -v | ||
shell: bash |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏