0

Currently I have 3 (same code base apps) with it's own databases and own unique data. Were moving towards doing multi tenancy in rails, after a couple of prototype testing we've decided to go for a shared tenancy. My only biggest problem is that, each databases have their own data with unique ids and etc. How would it be possible to merge them either via sql command/dump or rails script that way they will have their own account_id + keep all data integrity?

Berimbolo
  • 293
  • 2
  • 12

1 Answers1

0

Absolutely doable. It depends on a lot of details.

Basically I would

  1. Make a full backup of all three.
  2. Prep each database to hold compatible data (no duplicates).
  3. Select one to be the new master.
  4. Dump the other two (data only).
  5. Hack the dump, to make sure. Typical COPY statements in dumps are just fine.
  6. Restore data from the two additional database on top of existing data in the master.
  7. Make sure all sequences are set properly.
  8. Run vaccumdb -fz master.
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • 1
    Thanks for this one, though I've already came up with another solution using apartment gem, which allows me to dump the data and they are just segregated via schema. :) – Berimbolo Jul 25 '14 at 06:41
  • @Berimbolo: Of, course, if separate schemas are an option, that makes it much easier! I had understood that you wanted to merge data into same tables. – Erwin Brandstetter Jul 25 '14 at 13:01