59 lines
1.2 KiB
Markdown
59 lines
1.2 KiB
Markdown
# Migrator
|
|
|
|
Data-only migration tool between Postgres and SQLite using Drizzle.
|
|
|
|
## What it does
|
|
|
|
- Copies data from source to target
|
|
- Does NOT create or alter tables
|
|
- Overwrites target data if any rows exist (via `DELETE FROM` in dependency-safe order)
|
|
|
|
## Requirements
|
|
|
|
- Tables must already exist on the target database
|
|
- Schema must match the backend Drizzle schemas
|
|
|
|
## Usage
|
|
|
|
Run from repo root:
|
|
|
|
1) Edit the TypeScript config file:
|
|
|
|
`apps/migrator/migrator.config.ts`
|
|
|
|
2) Run migration:
|
|
|
|
```bash
|
|
bun --cwd apps/migrator run migrate
|
|
```
|
|
|
|
### Config fields (`apps/migrator/migrator.config.ts`)
|
|
|
|
- `from`: `postgres` or `sqlite`
|
|
- `to`: `postgres` or `sqlite`
|
|
- `source`: Postgres connection string or SQLite file path
|
|
- `target`: Postgres connection string or SQLite file path
|
|
- `batchSize`: optional batch size (default: `500`)
|
|
|
|
## Examples
|
|
|
|
```bash
|
|
Update `apps/migrator/migrator.config.ts` and run:
|
|
|
|
```bash
|
|
bun --cwd apps/migrator run migrate
|
|
```
|
|
```
|
|
|
|
```bash
|
|
Update `apps/migrator/migrator.config.ts` and run:
|
|
|
|
```bash
|
|
bun --cwd apps/migrator run migrate
|
|
```
|
|
```
|
|
|
|
## Notes
|
|
|
|
- IDs are copied as-is to preserve relationships.
|
|
- For Postgres targets, sequences may need manual reset after import.
|