better deploys
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 2m40s
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 2m40s
This commit is contained in:
80
.gitea/workflows/manual-db-reset.yml
Normal file
80
.gitea/workflows/manual-db-reset.yml
Normal file
@@ -0,0 +1,80 @@
|
||||
# FILE: .gitea/workflows/manual-db-reset.yml
|
||||
#
|
||||
# DANGER: This workflow is DESTRUCTIVE and intended for manual execution only.
|
||||
# It will completely WIPE and RESET the PRODUCTION database.
|
||||
#
|
||||
name: Manual - Reset Production Database
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
confirmation:
|
||||
description: 'DANGER: This will WIPE the production database. Type "reset-production-db" to confirm.'
|
||||
required: true
|
||||
default: 'do-not-run'
|
||||
|
||||
jobs:
|
||||
reset-database:
|
||||
runs-on: projectium.com # This job runs on your self-hosted Gitea runner.
|
||||
|
||||
env:
|
||||
# Use production database credentials for this entire job.
|
||||
DB_HOST: ${{ secrets.DB_HOST }}
|
||||
DB_PORT: ${{ secrets.DB_PORT }}
|
||||
DB_USER: ${{ secrets.DB_USER }}
|
||||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
DB_DATABASE: ${{ secrets.DB_DATABASE_PROD }} # Assumes a secret for the production DB name.
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Verify Confirmation Phrase
|
||||
run: |
|
||||
if [ "${{ gitea.event.inputs.confirmation }}" != "reset-production-db" ]; then
|
||||
echo "ERROR: Confirmation phrase did not match. Aborting database reset."
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Confirmation accepted. Proceeding with database reset."
|
||||
|
||||
- name: 🚨 FINAL WARNING & PAUSE 🚨
|
||||
run: |
|
||||
echo "*********************************************************************"
|
||||
echo "WARNING: YOU ARE ABOUT TO WIPE AND RESET THE PRODUCTION DATABASE."
|
||||
echo "This action is IRREVERSIBLE. Press Ctrl+C in the runner terminal NOW to cancel."
|
||||
echo "Sleeping for 10 seconds..."
|
||||
echo "*********************************************************************"
|
||||
sleep 10
|
||||
|
||||
- name: Step 1 - Drop All Tables from Production DB
|
||||
run: |
|
||||
echo "Executing drop_tables.sql against the PRODUCTION database..."
|
||||
PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_DATABASE" -f sql/drop_tables.sql
|
||||
echo "✅ All tables dropped successfully."
|
||||
|
||||
- name: Step 2 - Rebuild Schema from Master Rollup
|
||||
run: |
|
||||
echo "Executing master_schema_rollup.sql against the PRODUCTION database..."
|
||||
PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_DATABASE" -f sql/master_schema_rollup.sql
|
||||
echo "✅ Schema rebuilt successfully."
|
||||
|
||||
- name: Step 3 - Update Schema Info Table
|
||||
run: |
|
||||
echo "Updating schema_info table with the new schema hash..."
|
||||
# Calculate the hash of the current schema file.
|
||||
CURRENT_HASH=$(cat sql/master_schema_rollup.sql | dos2unix | sha256sum | awk '{ print $1 }')
|
||||
echo "New Schema Hash: $CURRENT_HASH"
|
||||
|
||||
# Insert the new hash into the freshly created schema_info table.
|
||||
PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_DATABASE" -c \
|
||||
"INSERT INTO public.schema_info (id, schema_hash, deployed_at) VALUES (1, '$CURRENT_HASH', NOW())
|
||||
ON CONFLICT (id) DO UPDATE SET schema_hash = EXCLUDED.schema_hash, deployed_at = NOW();"
|
||||
|
||||
# Verify the hash was updated
|
||||
UPDATED_HASH=$(PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_DATABASE" -c "SELECT schema_hash FROM public.schema_info WHERE id = 1;" -t -A)
|
||||
if [ "$CURRENT_HASH" = "$UPDATED_HASH" ]; then
|
||||
echo "✅ Schema hash successfully set in the database to: $UPDATED_HASH"
|
||||
else
|
||||
echo "ERROR: Failed to set schema hash in the database."
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user