-
Notifications
You must be signed in to change notification settings - Fork 69
Add development time yarn db:clear:all script for easy analytics data clearing #1041
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
259a4f3
add development time yarn db:clear:all script for easy analytics data…
rikukissa ca5f8d4
fix indent
rikukissa b27c4d9
drop analytics database as part of data clearing
rikukissa 6f15a51
Merge branch 'develop' of github.com:opencrvs/opencrvs-countryconfig …
rikukissa 9a71a61
cleanup
rikukissa adf4fae
Merge branch 'develop' of github.com:opencrvs/opencrvs-countryconfig …
rikukissa 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
This file contains hidden or 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
This file contains hidden or 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,61 @@ | ||
| #!/bin/bash | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| # | ||
| # OpenCRVS is also distributed under the terms of the Civil Registration | ||
| # & Healthcare Disclaimer located at http://opencrvs.org/license. | ||
| # | ||
| # Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | ||
|
|
||
| set -e | ||
|
|
||
| echo "🧹 Clearing all development data..." | ||
|
|
||
| # Default PostgreSQL connection parameters for development | ||
| POSTGRES_HOST=${POSTGRES_HOST:-localhost} | ||
| POSTGRES_PORT=${POSTGRES_PORT:-5432} | ||
| POSTGRES_USER=${POSTGRES_USER:-postgres} | ||
| POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres} | ||
| ANALYTICS_POSTGRES_USER=${ANALYTICS_POSTGRES_USER:-events_analytics} | ||
|
|
||
| print_usage_and_exit() { | ||
| echo 'Usage: ./clear-all-data-dev.sh' | ||
| echo "" | ||
| echo "Environment variables (with defaults for development):" | ||
| echo "POSTGRES_HOST=${POSTGRES_HOST}" | ||
| echo "POSTGRES_PORT=${POSTGRES_PORT}" | ||
| echo "POSTGRES_USER=${POSTGRES_USER}" | ||
| echo "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}" | ||
| echo "ANALYTICS_POSTGRES_USER=${ANALYTICS_POSTGRES_USER}" | ||
| echo "" | ||
| echo "This script clears all development databases including:" | ||
| echo "- PostgreSQL analytics schema and data" | ||
| echo "- Metabase configuration database (H2)" | ||
| echo "- Any additional custom databases (can be extended by country configurations)" | ||
| exit 1 | ||
| } | ||
|
|
||
| # Check if PostgreSQL is accessible | ||
| if ! PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -d postgres -c '\q' 2>/dev/null; then | ||
| echo "❌ Cannot connect to PostgreSQL at ${POSTGRES_HOST}:${POSTGRES_PORT}" | ||
| echo " Make sure PostgreSQL is running and credentials are correct." | ||
| print_usage_and_exit | ||
| fi | ||
|
|
||
| # Clear PostgreSQL analytics schema | ||
| echo "🗑️ Clearing PostgreSQL analytics schema..." | ||
| PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -d events -v ON_ERROR_STOP=1 <<EOSQL || echo "⚠️ Analytics schema may not exist yet" | ||
| -- Drop analytics schema and recreate it | ||
| DROP SCHEMA IF EXISTS analytics CASCADE; | ||
| CREATE SCHEMA analytics; | ||
|
|
||
| -- Drop and recreate analytics user | ||
| DROP ROLE IF EXISTS "$ANALYTICS_POSTGRES_USER"; | ||
| EOSQL | ||
|
|
||
| echo "✅ PostgreSQL analytics data cleared" | ||
|
|
||
| echo "" | ||
| echo "🎉 All development data cleared successfully!" | ||
| echo "" |
This file contains hidden or 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
This file contains hidden or 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
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.
The e2e repo needs any changes regarding this? I mean this will be different for each feature environment right?