freshyo/packages/migrator/README.md
2026-03-27 01:59:26 +05:30

84 lines
1.7 KiB
Markdown

# @packages/migrator
Database migration tool for moving data between PostgreSQL and SQLite.
## Setup
Install dependencies:
```bash
npm install
```
## Configuration
Edit `src/config.ts` directly to configure database settings:
```typescript
// PostgreSQL Configuration
export const postgresConfig = {
connectionString: 'postgresql://postgres:postgres@localhost:5432/freshyo',
ssl: false,
};
// SQLite Configuration
export const sqliteConfig = {
filename: './data/migrated.db',
};
// Migration Settings
export const migrationConfig = {
batchSize: 1000, // Rows per batch
truncateBeforeInsert: true, // Clear tables before migration
excludedTables: [], // Tables to skip
includedTables: [], // Tables to include (empty = all)
};
// Logging
export const logConfig = {
verbose: true,
logFile: './migration.log',
};
```
## Usage
### PostgreSQL to SQLite
Migrate data from PostgreSQL to SQLite:
```bash
npm run migrate:pg-to-sqlite
```
### SQLite to PostgreSQL
Migrate data from SQLite to PostgreSQL:
```bash
npm run migrate:sqlite-to-pg
```
### Full Cycle (Testing)
Run both migrations in sequence:
```bash
npm run migrate:full-cycle
```
## Features
- ✅ Automatic schema conversion between PostgreSQL and SQLite
- ✅ Batch processing for large datasets
- ✅ Type mapping between databases
- ✅ JSON/array handling
- ✅ Configurable table filtering
- ✅ Progress logging
- ✅ Transaction support
## Notes
- Arrays and JSON data are stored as TEXT in SQLite and parsed back when migrating to PostgreSQL
- Date/timestamps are stored as ISO strings in SQLite
- Foreign key constraints are enabled in SQLite
- Edit `src/config.ts` to change any settings