Migrate from Mongo to Postgres
Opened this issue · 1 comments
MongoDB got the job done for a while, but as we move to implement new features having a standard DB with tables will make life much easier.
Implementation
Table Schema
Only two tables for now:
user
- user_id (uuid)
- username (text)
- password_hash (text)
- registration_date (datetime)
- library (json)
list_external_id
- list_external_id (text)
- user_id (UUID)
Technology
Use knex for a query builder
Migration
Given how a server migration is imminent, the plan is to install postgres only on the new server, and have the web server still running on the old server, talking to postgres on the new server (in the same data center).
This migration intentionally has downtime to avoid a much more complicated and time-consuming zero-downtime migration.
Preparation
- Install postgres on the new server and configure to allow connections from localhost and the old server (including setting up an encrypted (ssl?) connection)
- Write script that can import a mongodump file to postgres
- Modify
server/views.js
andserver/endpoints.js
to talk to postgres instead of mongo in apostgres
branch - Create a database migrations folder with sql files named by date
2019-10-06-users-and-ids.sql
- Run through the execution steps with the beta site
Execution steps
- Merge the
postgres
branch to `master - Open terminals to new web server and old web server.
- Update
config/local.json
on the old server with connection values to the DB - Open SFTP connection from new server to old server
- Disable auto-restart of the lighterpack service on the old server. TODO: remember how to do this
stop lighterpack
mongodump
- SFTP transfer the mongodump'd file to the new web server
- Run the import script to populate the postgres db
git pull
on the old serverstart lighterpack
- Perform manual testing of logging in, saving data, and viewing a list
- Re-enable auto-restart of the lighterpack service on the old server TODO: remember how to do this
This seems like a waste of time. Let's add features!
Edit: To elaborate, I'm having a hard time understanding the necessity of changing DB tech. If there aren't cost, performance, or scalability concerns, moving from mongo to postgres seems like a high-effort/low-payoff move. Given that Galen has limited availability to work on things/complete PRs/etc, I'd vote that we address the data/schema concerns within the application instead.
Anyway, just my two cents, and I'll definitely support whichever direction we end up chasing!