Agent skill
database-reset-staging
Resets staging database with full schema drop. Use for schema changes or migrations. SINGLE SOURCE OF TRUTH for staging database reset automation.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/database-reset-staging
SKILL.md
Database Reset Staging Skill
Purpose: Full database reset for staging environment - drops all tables and lets migrations rebuild.
When to Use:
- Schema changes requiring clean slate
- Migration conflicts with existing tables
- Database corruption or inconsistencies
- After major refactoring
When NOT to Use:
- Just need fresh seed data (use selective delete instead, see database guide)
- Production database (NEVER - this is staging only)
Background Documentation: See /docs/guides-setup/database-setup.md (Staging Database Management section) for context and manual procedures.
🚨 CRITICAL WARNINGS
This skill performs DESTRUCTIVE operations:
- ❌ ALL data in staging database will be DELETED
- ❌ All tables will be DROPPED (not schemas - managed DB limitation)
- ❌ Cannot be undone
- ✅ ONLY affects staging database (
pgbouncer-staging) - ✅ Migrations will rebuild tables automatically
Note: DigitalOcean managed databases don't allow dropping the public schema (owned by doadmin). This skill drops all tables owned by witchcity_staging user instead.
Prerequisites:
- Staging code already deployed (use
staging-deployskill first) - Database backup if needed (though staging data is expendable)
How to Use This Skill
Executable Script: execute.sh
# From project root - with confirmation prompt
bash .claude/skills/database-reset-staging/execute.sh
# Skip confirmation prompt (for automation)
SKIP_CONFIRMATION=true bash .claude/skills/database-reset-staging/execute.sh
What the script does:
- Shows pre-flight information (purpose, when/when NOT to use, destructive operation warnings)
- Requires confirmation before proceeding (skippable with env var)
- Validates prerequisites:
- SSH key accessible
- PostgreSQL client installed (psql)
- Server connectivity
- Retrieves database credentials from staging server (from
.env.staging) - Stops API container
- Drops all tables owned by
witchcity_staginguser (CASCADE) - Starts containers (migrations run automatically)
- Waits for database initialization
- Verifies tables rebuilt
- Runs health check
- Reports summary
Script includes CRITICAL safety warnings - this is a DESTRUCTIVE operation that cannot be undone.
Manual Override (Emergency Only)
If skill fails, manual steps:
Prerequisites: Get DB credentials from server first
ssh witchcity@104.131.165.14 'cat /opt/witchcityrope/staging/.env.staging | grep STAGING_DB_CONNECTION_STRING'
Manual table drop: Connect to database and execute:
-- Generate DROP statements for all tables owned by witchcity_staging
SELECT 'DROP TABLE IF EXISTS "' || tablename || '" CASCADE;'
FROM pg_tables
WHERE schemaname = 'public' AND tableowner = 'witchcity_staging';
-- Then execute the generated statements
Then: Restart staging containers via SSH:
ssh witchcity@104.131.165.14 'cd /opt/witchcityrope/staging && docker compose -f docker-compose.staging.yml up -d --force-recreate api'
Common Issues & Solutions
Issue: psql command not found
Cause: PostgreSQL client not installed locally
Solution:
# Ubuntu/Debian
sudo apt install postgresql-client
# macOS
brew install postgresql
Issue: Connection timeout
Cause: Firewall or network issue
Solution:
- Verify server is accessible:
ssh witchcity@104.131.165.14 - Check staging containers: Use
restart-dev-containersskill - Verify database port is open (25060)
Issue: Migrations fail after reset
Cause: Old migration state or code/DB mismatch
Solution:
- Check API logs:
restart-dev-containersskill - Ensure latest code deployed:
staging-deployskill - Verify no lingering tables: Run query to list all tables
Issue: Seed data not populating
Cause: Seed condition not met
Solution:
- API only seeds if
appsettings.Staging.jsonhasSeedData: true - Check environment configuration on server
- Manual trigger: Restart API container with
restart-dev-containersskill
Integration with Process
Typical workflow:
- Make schema changes locally
- Test migrations locally
- Deploy code: Use
staging-deployskill - Reset database: Use THIS skill
- Verify: Use
restart-dev-containersskill to check logs
Version History
- 2025-12-09: Fixed to drop tables instead of schemas (DigitalOcean managed DB limitation)
witchcity_staginguser cannot droppublicschema (owned bydoadmin)- Now drops all tables owned by
witchcity_stagingwith CASCADE
- 2025-11-05: Created as automation wrapper for staging database reset
- Extracted from:
docs/functional-areas/deployment/staging-deployment-guide.md - Complements:
docs/guides-setup/database-setup.md
Remember: This skill is for staging only. Never use on production. Always use staging-deploy skill first to ensure latest code is deployed.
Didn't find tool you were looking for?