data-import icon indicating copy to clipboard operation
data-import copied to clipboard

Debug-Goodie: Make Mapping available after import via function on the imported entity

Open danielfrey opened this issue 12 years ago • 4 comments

As a goodie it would be extremely useful to be able to get the mapping any time after the import. Working with an imported database you often have the situation where you need to get the corrsponding ID of an imported object. Eg. say you have a person in the new database, you could ask it directly for it's "old" ID or get the new ID via a function given the old ID.

danielfrey avatar Nov 01 '12 07:11 danielfrey

I think this is related to #49. When we store the lookup-tables on disk we can also use them to provide this feature.

We should provide a global way to determine the "old ID", when given the "Definition Name", and the "new ID". This function should be accessible through the ExecutionPlan or a different object, which is known to the client. The final functionality could be packaged up in a Rake task.

I would not integrate it into ActiveRecord though. This can be done on a per-project basis when it's needed. We encourage that data-import lives in a separate project and is not available in your application.

senny avatar Nov 01 '12 07:11 senny

That's indeed pretty useful. I'm thinking of something like a rake task (or even multiple tasks) to get the id mappings.

Given the following definition:

definition 'people' do
  from 'tblPerson'
  to 'people'

  lookup_for :id, :column => :OID
  lookup_for :employee_number
end

I would then be able to get id mappings with the following commands:

# get the old id of the person with the new id 5
rake mappings:old_id[people, 5] # uses lookup 'id' by default

# get the new id of the employee which had an employee number of 18 in the old database
rake mappings:new_id[people, 18, employee_number]

The first parameter is the name of the definition, the second is the id you'd like to retrieve and the last parameter is the name of the lookup (which is 'id' if you don't specify anything).

What do you think about this? Other ideas?

stmichael avatar Nov 01 '12 07:11 stmichael

This feature is just for debugging purposes after the import happened, meaning you want to find out what objects form the source and target database are related. So we don't need ActiveRecord. We simply want to get old and new ids.

stmichael avatar Nov 01 '12 08:11 stmichael

@stmichael I was referring to the following phrase in the ticket:

Eg. say you have a person in the new database, you could ask it directly for it's "old" ID

senny avatar Nov 01 '12 08:11 senny