This project demonstrates how to migrate a high-transaction PostgreSQL database from a self-hosted environment to a cloud-based solution without any downtime or data loss.
We leverage DevCycle's feature flags and Drizzle ORM to:
- Dual Write Operations: Write to both old and new databases simultaneously.
- Conditional Read Operations: Gradually switch reads from the old database to the new one for specific user groups.
- Zero Downtime: Maintain uninterrupted service during the migration.
- Flexibility: Toggle database operations without redeploying.
- Control: Direct specific user groups to the new database.
- Safety: Quickly revert to the old database if needed.
- Performance: Ensure data consistency and reliability.
- Node.js
- PostgreSQL
- DevCycle Account
- Drizzle ORM
-
Clone the repository:
git clone https://github.com/jacksonkasi0/geo-feature-flag-db-migration.git
-
Navigate to the server app:
cd geo-feature-flag-db-migration/apps/server
-
Install dependencies:
deno install
-
Set up DevCycle feature flags:
- Create
write
andread
boolean flags. - Define user groups and conditions based on your requirements.
- Create
-
Update environment variables:
- Add your DevCycle SDK key.
- Configure database connection strings for both old and new databases.
Start the server:
deno task dev
- The application evaluates feature flags to determine database operations.
- Write Operations:
- If
writeToNewDB
istrue
, writes go to both databases. - Otherwise, writes go only to the old database.
- If
- Read Operations:
- If
readFromNewDB
istrue
, reads come from the new database. - Otherwise, reads come from the old database.
- If
- Under Development:
- Automating data synchronization with PostgreSQL's Publish-Subscribe feature.
- Building Docker containers and scripts for automation.
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License.
Feel free to explore the GitHub repository for more details.
Happy coding! 😊🚀