Any Strategies to Migrate Data to Postgres? Specifically Accounts (also using Apollo)


#1

Due to business needs changing I now need to have transactions which is something that Mongo doesn’t offer (though they do have a kludgey 2 phase commit scheme).

Migrating from Mongo to Postgres is simple enough especially since I made a facade like Posts.findById and Posts.insert. The clientside is slowly migrating to Apollo.

However, dealing with the user accounts is a bit tricky… i’d rather not roll my own auth after everything is in production and working (i’m also using an SMS login package). How have others dealt with this? Some options i’ve considered were:

1. Leaving the entire user in mongo and then having an unofficial ‘foreign key’ (user_id) on other tables that saves the ID but the relation is not enforced on the database level. Then GraphQL can make a query to pull in the user when needed.

2. Migrating the entire user to a new users table and adding a mongo_id field to the row so that it’s saved for looking up purposes

3. Same as #2 but instead having a string ID using the same ID from the current mongo user IDs… this would allow you to use the mongo doc for auth only and in the system refer to the postgres user

4. Migrate users and don’t have them in Mongo at all… re-writing authentication. Honestly I don’t think there’s enough time to do this and can be very hard to estimate timelines for a migration.


#2

Did you consider alternatives like Auth0? https://auth0.com


#3

Have you looked at the (sort of) official conversion of the Meteor accounts system to PG?


#4

I’ve considered it but it seems like more of a hassle and expensive once things grow.


[quote="robfallows, post:3, topic:30097, full:true"] Have you looked at the (sort of) official conversion of the Meteor accounts system to PG? [/quote]

Hmmm I forgot about this… didn’t know they open sourced it. However, I def. don’t want to tie accounts down to a spiked repo.


I’m leaning on #1 for now and then eventually when the users are the last MongoDB vestige, just migrate them to a new table and drop in standard auth.