# DB Reset

> Reset and seed database for development or testing. Use when needing fresh database state, running migrations, or seeding test data.

- Skill: `allanninal/db-reset` (Agent Skill)
- Install (CLI): `npx skillmds@latest add allanninal/db-reset`
- Raw SKILL.md: https://api.skillmd.com/api/skills/allanninal/db-reset/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: allanninal (https://skillmd.com/u/allanninal)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/allanninal/db-reset

---


# Database Reset & Seed

Reset databases to a clean state and optionally seed with test data.

## Arguments
- `$ARGUMENTS`: Project name (optional - uses current directory if not specified)

## IMPORTANT WARNINGS

- **NEVER run on production databases**
- **Always backup before reset**
- Confirm with user before destructive operations

## Database Configurations

| Project | Database | Connection | Seed Script |
|---------|----------|------------|-------------|
| eruditiontx-services-mvp | MongoDB | `mongodb://localhost:27017/eruditiontx_db` | `scripts/seed.py` |
| mathmatterstx-services | MongoDB | `mongodb://localhost:27017/mathmatters_db` | `scripts/seed.py` |
| notaryo.ph | PostgreSQL | `.env.local` DATABASE_URL | `prisma/seed.ts` |
| bocs-turbo | Various | Per app config | Per app |

## Execution Steps

### 1. Backup Current Database

**MongoDB:**
```bash
mongodump --db=$DB_NAME --out=./backup/$(date +%Y%m%d_%H%M%S)
```

**PostgreSQL:**
```bash
pg_dump $DATABASE_URL > ./backup/$(date +%Y%m%d_%H%M%S).sql
```

### 2. Reset Database

**MongoDB:**
```bash
mongosh --eval "use $DB_NAME; db.dropDatabase();"
# or with authentication
mongosh mongodb://localhost:27017/$DB_NAME --eval "db.dropDatabase();"
```

**PostgreSQL (Prisma):**
```bash
npx prisma migrate reset --force
# This drops, recreates, and runs all migrations
```

### 3. Run Migrations

**MongoDB (Beanie):**
Beanie auto-creates collections from models. No explicit migration needed.

**PostgreSQL (Prisma):**
```bash
npx prisma migrate deploy
# or for development
npx prisma migrate dev
```

### 4. Seed Database

**Python Projects:**
```bash
# If seed script exists
uv run python scripts/seed.py
# or
uv run python -m app.database.seed
```

**Prisma Projects:**
```bash
npx prisma db seed
# Runs the seed script defined in package.json
```

## Test Database Reset

For running tests with clean database:

**Python (pytest):**
```bash
# Create test database
mongosh --eval "use eruditiontx_test_db; db.dropDatabase();"

# Run tests (they should seed their own fixtures)
uv run pytest --db-reset
```

**JavaScript:**
```bash
# Usually handled by test setup
npm run test:db-reset
```

## Common Seed Data

### User Roles (Erudition Projects)
- Admin users
- Staff users
- Teacher users
- Student users

### Sample Data
- Test schools/organizations
- Sample questions/content
- Test transactions

## Output Format

```
Database Reset: [project-name]
Database Type: [MongoDB/PostgreSQL]
Database Name: [db-name]

1. Creating backup...
   Backup saved: ./backup/[timestamp]

2. Dropping database...
   Database dropped.

3. Running migrations...
   [Migration output]

4. Seeding data...
   [Seed output]

Database reset complete!
Records created:
  - Users: X
  - [Other models]: Y
```

## Recovery

If something goes wrong:

```bash
# MongoDB
mongorestore --db=$DB_NAME ./backup/[timestamp]/$DB_NAME

# PostgreSQL
psql $DATABASE_URL < ./backup/[timestamp].sql
```

