[Refactor] Reconnecting Data with Foreign Keys
refactor
Web icon
Forge component by Francisco Menezes
Application Type
Traditional Web

Hello,

I just recently used the Refactor application. I wanted to move multiple data from one espace to another. In this example I want to move a total of three entity to a newly created core module. I follow the steps documented in the Move Entity section in Refactor application. 

I copy the entities over to the target espace module. This includes the static entity. I follow the remaining steps. Once I get to pass step 2.c running full compilation solution with the source and target espace. I notice that two of three entities only move. The Country and Person entity data has been moved but PersonAddress did not. I double check the Move Entity table in Refactor application to see if the PersonAddress entity was moved and a record for PersonAddress does exist.

If I try to run another solution, I will get a foreign key constraint on PersonId and CountryId for PersonAddress entity.

To tackle this issue of mine, I tried running the move actions sequentially for all entities in a single timer and individual. Both case I have ran into this same issue. I would like to know how and why the PersonAddress entity won't move to the target espace. 

Is there a step I'm misinterpreting or is this a limitation for Refactor? 

I appreciate your time.

Thank you,
Michael 

Entity Diagram.png

Hello Michael,

I've also tried to use this component on a project (we've decided to go with a scripted data migration instead) but, while investigating the component, we were able to move dummy data similar to yours.

I believe you can't copy the static unless you're also gonna included it in the refactor flow. If you're going to leave it in the source module, you should only copy the 3 you want to move, and then add the reference to the Gender entity.

Since you have references between entities, they should be all in the OnPublish flow and ordered: Country, Person, PersonAddress.

If you're trying multiple times to move the data, you should delete the records in the "MovedEntity" table, since there's a step to validate if the entity was already moved, and then try again.

I hope this helps you,

Laura

Hello Laura,

Thank you for the response, I will try to remove the records in the "MoveEntity" table after every entity and let you know how that goes.

As for the statics, I did create a new version of Gender in our Target core espace during step 1.c.

As for the order of the move action. I did follow the structure like you mention. Trying to move the base entity/entity with no references first. Like you mention in your post, that was the order I followed Country, Person than PersonAddress. 

Most of the time the Country and Person data move over with no issue. It was only until I got to PersonAddress it had issues. The data would not connect but the information such as event table name and physical table name was swapped. 

Other times when moving Country (first). When performing step 2.c I would get FK constraints on PersonAddress. I tried to add the new Country entity as a dependency in the source espace where PersonAddress lives. However, that never solved my issue.  

Hope the additional information helps.

Thank you,

Michael

Hello Laura,

I would like to apologize delay. Due to several testing scenarios, I had to rebuild the same data structure as I mention in the example to test.

With your recommendation on removing the record in "MoveEntity" after each move. I didn't run into any trouble with foreign key constraints. As you know the foreign key constraints would be for County and PersonAddress and/or Person and PersonAddress. This was dependent on if I was moving Country or Person at the given point.

When moving PersonAddress, I still had the issue where I followed the documentation. After step 2.c "In Service Center create a solution containing <Source eSpace> and <Target eSpace> espaces and then publish the solution with full compilation" The data still hasn't been moved.

If there any additional information or you need me to clarify anything. Please let me know.

Thank you,

Michael 

Hey Michael,

It's okay, no need for apologies. 

I've recreated your data model, given it a go, and didn't find any issues during the process. I've also tried leaving the Gender static entity in the source module and also copying it to the target module and didn't find any problem.

I might be missing some part of your process, but are you trying to move the 3 entities at once?

This is how I have my "OnPublish" action in the Refactor module

Also, can you give more details about the error you're having?

Thank you,

Laura


Hello Laura,

In the very beginning when trying to move the entities. I structure the OnPublish action exactly like you did in your image above. With three Entity move action one after the other. With the order of Country, Person, then Person Address(just like your image). 

After reading the documentation "Entity_Move declarations only act once, allowing to add them incrementally as you move entities step by step". I interpreted this to mean that we can only move one entity at a time. Therefore, my OnPublish action looks more like the image below.

I would move one entity at a time and fix all the issues and references during step 3 and 4. I would repeat this step for the other entities in the same order of Country, Person, Person Address.

As for the error, this happen when trying to move a single entity like Country and Person and Person Address still has data in the source espace. Since the Id for either Country or Person doesn't exist anymore in the source espace (since the data was move to the target espace). I would get a foreign key error during 2.c solution. I would like to state that after performing your recommendation, I haven't got that error to appear again.

 


Thank you for your clarifications, Michael.

I understand your confusion with the documentation. "Entity_Move declarations only act once, allowing to add them incrementally as you move entities step by step" means that each server action in the flow only runs once, allowing you to have multiple in the flow, and to move multiple data at once.

So you should have the 3 actions to prevent getting the foreign key constraint error.

If after deleting all records from the entity "MovedEntity", and having the 3 actions in the flow, you still can't move the data from the PersonAddress, I really don't know what else I can do to help you. I'm sorry.

To test you case, I did the following steps:

1- created my Source_CS module with the data model you gave, and added some data to the entity

2- created my Target_CS module, copied all entities

3- built the OnPublish action like the image above

4- published the Refactor module

5- published a solution with the 2 modules, with full compilation

Did you do something different?


Hello Laura,

You don't need to be sorry. You took time out of your busy day and helped me out a lot.
As for the steps, I didn't do anything different. I going to try the example that you gave with all the move action in the On Publish. I will keep you posted.

Thank you,

Michael

Hello,

After getting into contact with OutSystem's we discover the issue was due to multi-tenancy. Refactor was not set up for this scenario. OutSystem's recommended two options:

1. With direct database access and run a script to move the data from one application to another. (Will need to request access from OutSystems)

2. Create a process to switch tenant and manually create data in the new module. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.