# Database Schema

## Entity Relationship Diagram

```
┌──────────┐       ┌──────────┐       ┌─────────────┐       ┌──────────┐
│  USERS   │──1:N──│  ORDERS  │──1:N──│ ORDER_ITEMS │──N:1──│ PRODUCTS │
│──────────│       │──────────│       │─────────────│       │──────────│
│ id    PK │       │ id    PK │       │ id       PK │       │ id    PK │
│ email    │       │ user_id FK│       │ order_id FK │       │ name     │
│ name     │       │ status   │       │ product_id FK│       │ price    │
│created_at│       │created_at│       │ quantity    │       └──────────┘
└──────────┘       └──────────┘       └─────────────┘
```

## Tables

### Table: {table_name}

**Description**: {What this table stores and its role in the system.}

#### Columns

| Column | Type | Nullable | Default | Constraints | Description |
|--------|------|----------|---------|-------------|-------------|
| id | UUID | No | gen_random_uuid() | PRIMARY KEY | Unique identifier |
| {column_name} | {type} | {Yes/No} | {default or —} | {UNIQUE, CHECK, etc.} | {description} |
| {column_name} | {type} | {Yes/No} | {default or —} | {constraints} | {description} |
| created_at | TIMESTAMPTZ | No | now() | — | Record creation time |
| updated_at | TIMESTAMPTZ | No | now() | — | Last modification time |

#### Indexes

| Name | Columns | Type | Description |
|------|---------|------|-------------|
| {index_name} | {column(s)} | BTREE / GIN / GIST / HASH | {why this index exists — what query it optimizes} |
| {index_name} | {column(s)} | UNIQUE | {enforces uniqueness on...} |

#### Foreign Keys

| Column | References | On Delete | On Update | Description |
|--------|-----------|-----------|-----------|-------------|
| {column} | {table.column} | CASCADE / SET NULL / RESTRICT | CASCADE | {description} |

---

### Table: {next_table_name}

**Description**: {What this table stores.}

#### Columns

| Column | Type | Nullable | Default | Constraints | Description |
|--------|------|----------|---------|-------------|-------------|
| id | UUID | No | gen_random_uuid() | PRIMARY KEY | Unique identifier |

#### Indexes

| Name | Columns | Type | Description |
|------|---------|------|-------------|

#### Foreign Keys

| Column | References | On Delete | On Update | Description |
|--------|-----------|-----------|-----------|-------------|

---

## Relationships Summary

| Relationship | Type | Description |
|-------------|------|-------------|
| {table_a} -> {table_b} | One-to-Many | {description} |
| {table_c} -> {table_d} | Many-to-Many (via {junction}) | {description} |
| {table_e} -> {table_f} | One-to-One | {description} |

## Migration Notes

- {Any special migration considerations}
- {Data backfill requirements}
- {Backward compatibility notes}
