Hi,

We have two databases with exactly the same DO.NET domain version. We would like to merge one of the database into the other one. Most of our entities keys are of type 'long' (not Guid), so a insert into dst select from src wouldn't work I think. I am thinking of using reflection and browse fields in domain to recreate all entities. However this will be quite a lot of work (not all entities have parameterless constructor, there are circular referencies, ect)

Do you have any advices on how to merge two databases ?

Regards, Benoit

asked Mar 21 at 12:14

Benoit%20Nesme's gravatar image

Benoit Nesme
33161924


One Answer:

Hello Benoit Nesme,

If you have exactly the same domain model in both databases then this is relatively simple merge. Say, we have a 'master' database and a 'slave' one and we are going to inflow data from the 'slave' to the 'master'. Just perform following things:

1) Backup both databases.

2) compare content of Metadata.Type and make sure that each type has the same type id in both databases. If they are equal then go to the next step. Otherwise, you need to correct type ids of the 'slave' in order to have the same type ids as in the 'master'. Each table containing TypeId column should updated with correct type ids.

3) Add to every ID value in the slave some skip value. For instance, if the master had IDs from 1 to 234 567 and the slave had IDs form 1 to 223 344 then we could add 300 000 to each ID in the slave so they would be from 300 001 to 523 344 and would not interfere with each other.

4) Copy data using INSERT INTO dst SELECT FROM src.

5) Validate that everything is copied successfully and correctly.

6) Change settings of Key generators so they will not generate keys lower than new maximum of key values.

By the way, DataObjects.Net 5.0 has a feature allowing to add storage nodes to domain - each node shares domain model and can work with its own schema or database and after building a domain and additional nodes you need to choose some node for certain session and work with it separately.

answered Mar 26 at 06:15

Alexey%20Kulakov's gravatar image

Alexey Kulakov
56715

Hi Alexey,

I think adding a value to each ID is quite a good idea, I am going to think about it. About the storage node, lets say we have the following existing data : - master has Documents with ID 1, 2, 3 - slave has Documents with ID 1, 2, 3 What happens if I configure a domain with both nodes and do a Query.All<document>().ToList() ?

(Mar 26 at 07:22) Benoit Nesme Benoit%20Nesme's gravatar image

Each node is separate from each other. One session can work with one node at a time. Before some action in session you choose which node you are going to work with. So if you choose the master node you will get records with its 1, 2, 3 and if you choose the slave node you will get only slave database records. There is no way to get records from each node during one session.

(Mar 27 at 00:38) Alexey Kulakov Alexey%20Kulakov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA