---
name: db
description: Database operations - run migrations, seed data, open Prisma Studio, reset, or inspect schema. Use when the user needs to work with the database.
argument-hint: [action]
allowed-tools: Bash, Read
disable-model-invocation: true
---

# Database Operations

Manage the PostgreSQL database via Prisma. All commands target the backend at `C:/Users/pi/projects/rea/main/backend`.

Parse `$ARGUMENTS` for the action.

## Actions

### `migrate` (default)
Run pending migrations against the local database.
```bash
docker exec rea-backend sh -c "cd /home/site/wwwroot && npx prisma migrate deploy"
```

### `migrate:dev`
Create a new migration during development.
```bash
docker exec rea-backend sh -c "cd /home/site/wwwroot && npx prisma migrate dev --name $ARGUMENTS[1]"
```
Requires a migration name as the second argument.

### `seed`
Seed the database with test data.
```bash
docker exec rea-backend sh -c "cd /home/site/wwwroot && npm run db:seed"
```

### `reset`
Reset the database (drops all data, re-runs migrations and seed). **Confirm with user before running.**
```bash
docker exec rea-backend sh -c "cd /home/site/wwwroot && npx prisma migrate reset --force"
```

### `studio`
Open Prisma Studio for visual database browsing.
```bash
docker exec rea-backend sh -c "cd /home/site/wwwroot && npx prisma studio"
```
Note: Prisma Studio runs on port 5555 inside the container. The user may need to map this port.

### `schema`
Display the current Prisma schema.
Read the file: `C:/Users/pi/projects/rea/main/backend/prisma/schema.prisma`

### `generate`
Regenerate the Prisma client after schema changes.
```bash
docker exec rea-backend sh -c "cd /home/site/wwwroot && npx prisma generate"
```

### `status`
Show migration status.
```bash
docker exec rea-backend sh -c "cd /home/site/wwwroot && npx prisma migrate status"
```

## Notes
- The database container must be running (`docker-compose up -d db`)
- Connection string: `postgresql://dev:dev@db:5432/realestate` (inside Docker network)
- Adminer UI available at http://localhost:8080 (server: `db`, user: `dev`, pass: `dev`, db: `realestate`)
