Import from one database to another, with identifier fields

I have a Ruby on Rails application that has two active environments: Stageand Production. Our development team uses Stage, but we would like to transfer our data to the production server for various reasons. However, the new database has a conflicting identifier, so it is not as simple as pulling data from one place and inserting it into another. For example, let's say we have a table called Widgets:

Widget:
  id: 9836
  name: "Staging widget"
  parent_id: 9635
  container_id: 533

If the above data is one of our widgets, we cannot import because there is already a widget with ID 9836and / or there is already a container with ID 533, that is, we will need to scan the association chain to create new containers before placing widgets in them.

We use MySQL databases for both environments. I was thinking about importing, and just adding 10,000 to all the corresponding columns that end in _id, as this will push us beyond the conflicting borders, but this seems like a bad decision.

Are there any tools, projects or ideas that can help me solve this problem?

+3
3

, . .

+1

, , . , , , , .

+1

, ( , MySQL ) - SQL ( RoRails, PHP w/MySQL, apolgize, )

id

Another option is to use a program like phpMyAdmin (yes, it's php), which is essentially a database GUI tool. With phpMyAdmin, you can export table selection fields. Just export all the EXCEPT data in the ID field, and then you can simply start importing that data.

This part I'm a little fuzzy. I think you have a file with a Widget file. If so, create a script that goes through each row of data and makes a Widget file.

0
source

Source: https://habr.com/ru/post/1767171/


All Articles