1.7 KiB
1.7 KiB
@packages/migrator
Database migration tool for moving data between PostgreSQL and SQLite.
Setup
Install dependencies:
npm install
Configuration
Edit src/config.ts directly to configure database settings:
// 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:
npm run migrate:pg-to-sqlite
SQLite to PostgreSQL
Migrate data from SQLite to PostgreSQL:
npm run migrate:sqlite-to-pg
Full Cycle (Testing)
Run both migrations in sequence:
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.tsto change any settings