A Node.js package to easily migrate data from MySQL to PostgreSQL databases.
- Migrate entire databases or specific tables
- Automatic data type mapping
- Support for primary keys, foreign keys, and indexes
- Handles NULL values and defaults
- Batch processing for large tables
- Sequence reset functionality
- Detailed migration status reporting
npm install mysql-to-postgres-migrator
const { migrateData } = require('mysql-to-postgres-migrator');
const config = {
mysql: {
host: 'localhost',
user: 'root',
password: 'password',
database: 'source_db'
},
postgres: {
host: 'localhost',
user: 'postgres',
password: 'password',
database: 'target_db',
port: 5432
},
options: {
tables: [], // Empty array means migrate all tables
primary: true,
notNull: true,
default: true,
resetSequences: true,
batchSize: 1000
}
};
async function migrate() {
try {
const result = await migrateData(config);
console.log('Migration completed:', result);
} catch (error) {
console.error('Migration failed:', error);
}
}
migrate();
host
: MySQL host addressuser
: MySQL usernamepassword
: MySQL passworddatabase
: Source database name
host
: PostgreSQL host addressuser
: PostgreSQL usernamepassword
: PostgreSQL passworddatabase
: Target database nameport
: PostgreSQL port (default: 5432)
tables
: Array of table names to migrate (empty array for all tables)primary
: Include primary key constraints (default: true)notNull
: Include NOT NULL constraints (default: true)default
: Include DEFAULT values (default: true)resetSequences
: Reset sequences after migration (default: true)batchSize
: Number of rows to insert in each batch (default: 1000)
The migration function returns an object with:
success
: Array of successfully migrated tablesfailed
: Array of failed tablesempty
: Array of empty tablesdetails
: Object with detailed information about each table's migration
MIT
Contributions are welcome! Please feel free to submit a Pull Request.