# Local DynamoDB + Data Import

This repo includes two scripts to:

1. Spin up DynamoDB Local with a persistent volume, create required tables, and launch the dynamodb-admin UI.
2. Copy rows from your local Postgres `bots_generatedclip` table into the DynamoDB `clip-meta-heavy` table.

## Prerequisites

- Docker
- AWS CLI
- `uv`

## 1) Start DynamoDB Local and Admin UI, create tables

Run the shell script (idempotent):

```bash
export AWS_SECRET_ACCESS_KEY="local"
export AWS_ACCESS_KEY_ID="local"
scripts/local_lyrics_migration/bootstrap.sh
```

What it does:

- Creates Docker volume `dynamodb_data`
- Runs DynamoDB Local and creates tables:
  - `clip-meta-heavy` (PK: `clipId`)
  - `clip-gen-config` (PK: `clipId`, SK: `type`)
  - `item-info` (PK: `itemId`, SK: `type`)
- Starts `dynamodb-admin` UI

Defaults:

- DynamoDB Local endpoint: `http://localhost:8123`
- Admin UI: `http://localhost:8124`

Override ports per run:

```bash
export AWS_SECRET_ACCESS_KEY="local"
export AWS_ACCESS_KEY_ID="local"
DDB_PORT=8000 ADMIN_PORT=9002 scripts/local_lyrics_migration/bootstrap.sh
```

## 2) Copy data from Postgres to DynamoDB

Run the importer:

```bash
uv run scripts/migrate_local_lyrics.py
```

Mappings:

- Postgres `bots_generatedclip.id` → Dynamo `clipId`
- Postgres `bots_generatedclip.prompt_text` → Dynamo `prompt_text`
- Postgres `bots_generatedclip.metadata->prompt` → Dynamo `prompt`

Defaults:

- Postgres: `postgres://suno@localhost:5432/suno_studio`
- DynamoDB endpoint: `http://localhost:8123`
- DynamoDB table: `clip-meta-heavy`

Custom example:

```bash
uv run scripts/copy_rds_to_dynamodb.py \
  --db-url postgres://suno@localhost:5432/suno_studio \
  --ddb-endpoint http://localhost:8123 \
  --table clip-meta-heavy \
  --limit 1000
```

## Troubleshooting

- Verify tables:

```bash
aws dynamodb list-tables --endpoint-url http://localhost:8123
```

- Open UI: `http://localhost:8124`
- If running admin in Docker, it connects to `http://host.docker.internal:<DDB_PORT>`.
