# Data Model: Refactor CLI Scripts to Web Application

## 1. Connection Configuration

To support the "Dataset Mapper" tool with reusable connections (as per spec), we need a way to store external database credentials.

### Entity: `ConnectionConfig`

*   **Table**: `connection_configs`
*   **Purpose**: Stores credentials for external databases (e.g., PostgreSQL) used for column mapping.

| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| `id` | UUID | Yes | Primary Key |
| `name` | String | Yes | User-friendly name (e.g., "Production DWH") |
| `type` | String | Yes | Enum: `postgres`, `excel` (future) |
| `host` | String | No | DB Host (for postgres) |
| `port` | Integer | No | DB Port (for postgres) |
| `database` | String | No | DB Name (for postgres) |
| `username` | String | No | DB User (for postgres) |
| `password` | String | No | Encrypted/Obfuscated password (for postgres) |
| `created_at` | DateTime | Yes | Creation timestamp |
| `updated_at` | DateTime | Yes | Last update timestamp |

## 2. Tool Request/Response Models (Pydantic)

These models define the API contracts for the new tools.

### Search Tool

#### `SearchRequest`
```python
class SearchRequest(BaseModel):
    env: str  # e.g., "dev", "prod"
    query: str # Regex pattern
```

#### `SearchResultItem`
```python
class SearchResultItem(BaseModel):
    dataset_id: int
    dataset_name: str
    field: str
    match_context: str
    full_value: str
```

#### `SearchResponse`
```python
class SearchResponse(BaseModel):
    results: List[SearchResultItem]
    count: int
```

### Debug Tool

#### `DebugDbRequest`
```python
class DebugDbRequest(BaseModel):
    source_env: str
    target_env: str
```

#### `DebugDbResponse`
```python
class DebugDbResponse(BaseModel):
    source_db_count: int
    target_db_count: int
    details: Dict[str, Any] # Full JSON dump
```

#### `DatasetStructureRequest`
```python
class DatasetStructureRequest(BaseModel):
    env: str
    dataset_id: int
```
