This Node.js script facilitates data migration from a MySQL database to a PostgreSQL database. It automates creating tables, indexes, foreign keys, and data insertion while maintaining data integrity.
- Node.js installed
- MySQL and PostgreSQL servers running
mysql2
andpg
NPM packages installed
Set up your database connection details at the beginning of the script:
// MySQL configuration
const mysqlConfig = {
host: 'localhost',
user: 'root',
password: 'root',
database: 'users',
port: 3306
};
// PostgreSQL configuration
const postgresConfig = {
host: 'localhost',
user: 'postgres',
password: 'postgres',
database: 'users',
port: 5432
};
- Converts MySQL data types to PostgreSQL-compatible types.
- Creates tables, primary keys, indexes, and foreign keys in PostgreSQL.
- Migrates data with null value handling and type conversion.
- Detailed migration process logging.
- Adjust the connection settings for your databases.
- Run npm install && npm run start
- Monitor the process as the script migrates each table.
- Supports auto-increment fields, enumerations, and JSON fields.
- SSL configuration for PostgreSQL is available but commented out.
- Assumes no restrictive constraints in MySQL that hinder direct migration.
Contributions for improvements or new features are welcome. Feel free to fork and submit pull requests.
This project is licensed under the MIT License. See the LICENSE file for more details.