> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spn.wtf/llms.txt
> Use this file to discover all available pages before exploring further.

# Mahalaxmi - Database

> MySQL schema, Drizzle ORM setup, and migration commands

## Overview

**MySQL 8** managed via **Drizzle ORM**. Schema is defined in `shared/schema.ts` — this is the single source of truth for all tables and types.

## Local database (Docker)

```bash theme={null}
# Start
docker-compose up mysql -d

# Connect via CLI
docker-compose exec mysql mysql -u dbuser -psin90is1 sahyogi

# Stop (keeps data)
docker-compose down

# Nuke everything (DELETES ALL DATA)
docker-compose down -v
```

Local credentials:

* Host: `localhost:3306`
* Database: `sahyogi`
* User: `dbuser`
* Password: `sin90is1`

## Production database

Hosted on a managed MySQL instance (PlanetScale or equivalent — confirm with team lead for exact host). Connect with `DATABASE_SSL=true`.

> Ask the team lead for prod DB credentials. Never commit credentials to git.

## Migration commands

```bash theme={null}
# Push schema changes directly to DB (dev — no migration files)
npm run db:push

# Generate SQL migration files
npm run db:migrate

# Seed the database with initial data
npm run db:seed

# Specific migration scripts
npm run db:setup-subscriptions
npm run db:add-user-fields
npm run db:create-access-control
npm run db:seed-access-control
npm run db:add-stripe-price-id
```

Drizzle config: `drizzle.config.ts` — outputs migrations to `./db/migrations/`, reads schema from `./shared/schema.ts`.

## Key tables

| Table                           | Purpose                                                                  |
| ------------------------------- | ------------------------------------------------------------------------ |
| `users`                         | User accounts, Stripe info, coin balance                                 |
| `bots`                          | AI bot configurations                                                    |
| `channels`                      | Channel integrations (whatsapp, telegram, gmail, web, twitter, linkedin) |
| `gupshup_whatsapp_integrations` | Gupshup WhatsApp account config                                          |
| `whatsapp_accounts`             | WhatsApp Business API accounts                                           |
| `conversations`                 | Conversation threads                                                     |
| `messages`                      | Individual messages                                                      |
| `whatsapp_message_info`         | Delivery/read receipts                                                   |
| `campaigns`                     | Campaign templates and state                                             |
| `contacts`                      | Customer contacts                                                        |
| `contact_lists`                 | Contact list groups                                                      |
| `credentials`                   | Encrypted API keys / OAuth tokens                                        |
| `integrations`                  | Third-party integration records                                          |
| `tools`                         | Bot tools/extensions                                                     |
| `webhooks`                      | User-defined webhooks                                                    |
| `training_files`                | Uploaded PDFs for RAG                                                    |
| `training_urls`                 | URLs scraped for RAG                                                     |
| `plans`                         | Subscription plan definitions                                            |
| `subscriptions`                 | User subscription state                                                  |
| `teams` / `team_members`        | Team management                                                          |
| `roles` / `permissions`         | RBAC definitions                                                         |
