#MySQL to PostgreSQL Migration Guide
This guide outlines the process for migrating data from a MySQL database to PostgreSQL for the 5CRSE Payload CMS application.
#Prerequisites
- Node.js 18+ installed
- Access to the source MySQL database
- Running PostgreSQL database (using Docker)
.envfile configured with appropriate connection details
#Environment Setup
- Copy the example environment file:
cp .env.example .env
- Update the
.envfile with your actual MySQL connection details:
# MySQL Connection Details
MYSQL_HOST=your_mysql_host
MYSQL_USER=your_mysql_username
MYSQL_PASSWORD=your_mysql_password
MYSQL_DATABASE=aystate
#Installation
Install the required dependencies for the migration process:
node src/scripts/install-migration-deps.js
This will add the necessary packages:
mysql2: MySQL client for Node.jspg: PostgreSQL client for Node.jsdotenv: Environment variable management
#Migration Process
The migration is handled by the migrate-mysql-to-postgres.js script, which performs the following steps:
- Connects to both MySQL and PostgreSQL databases
- Extracts data from MySQL tables
- Transforms the data to match the Payload CMS schema
- Imports the transformed data into PostgreSQL
- Closes all database connections
#Running the Migration
To run the migration process:
node src/scripts/migrate-mysql-to-postgres.js
The script will display detailed logs of the migration process, including:
- Connection status for both databases
- Records being migrated for each table
- Successful insertions or skipped duplicates
- Any errors encountered during the process
#Migration Order
The migration occurs in the following order to respect dependencies:
- User Roles
- Vehicles (including vehicle images)
- Dining (including location and images)
- Events (including location, images, and categories)
#Troubleshooting
#Connection Issues
If you encounter connection issues:
- Verify your MySQL credentials in the
.envfile - Ensure the MySQL server is accessible from your environment
- Check that the PostgreSQL Docker container is running:
docker ps | grep postgres
#Data Mapping Issues
If you encounter issues with data mapping:
- Check the table structure in MySQL to ensure it matches the expected schema
- Review the schema in PostgreSQL to ensure it's compatible with the mapped data
- Adjust the mapping functions in the migration script if necessary
#Running Out of Memory
For large databases, you might encounter memory issues. In this case:
- Consider running the migration in smaller batches
- Use pagination in your MySQL queries to limit the amount of data processed at once
- Increase the available memory for Node.js:
export NODE_OPTIONS=--max-old-space-size=4096
#Post-Migration Verification
After completing the migration, verify that all data has been successfully migrated:
- Check that all user roles are present in PostgreSQL
- Verify vehicle data, including images
- Confirm dining records are accessible in the Payload CMS admin interface
- Test event data, ensuring relationships and images are correctly linked
#Support
If you encounter any issues during the migration process, please refer to:
- Payload CMS documentation: https://payloadcms.com/docs
- PostgreSQL documentation: https://www.postgresql.org/docs/
- MySQL documentation: https://dev.mysql.com/doc/
#Need Additional Help?
If you require additional assistance with the migration process, please contact the development team.
#License
This migration tool is part of the 5CRSE application and is subject to the same licensing terms as the main application.
