AvroCsvBundle icon indicating copy to clipboard operation
AvroCsvBundle copied to clipboard

Added ImportIndex annotation and support for updating DB instead of just inserting

Open jp31415926 opened this issue 12 years ago • 3 comments

I needed a way to import changes to existing records instead of deleting them by hand and then importing. This code does that by annotating "ImportIndex" fields that are used to find an existing and update it (if it exists).

Also removed unneeded table in the import template and other minor changes.

Hope you can use it.

jp31415926 avatar Jan 05 '13 08:01 jp31415926

Updating your db with a csv?? I don't think this is a very good idea.

The first import would work, but how does the second import account for any rows added by the application? You would have to manually map the id's or generate unique id's instead of having them increment.

jdewit avatar Jan 05 '13 15:01 jdewit

Look at the code. It loads a record that matches the index-annotated fields. If it finds it, it updates the rest of the fields with the new values, but keeps the same id. If it doesn't, it creates a new record (entity).

This is something we use all the time to upload game schedules. Some mass changes are much easier with excel, so we export, change, and re-import the data.

On 1/5/13, jdewit [email protected] wrote:

Updating your db with a csv?? I don't think this is a very good idea.

The first import would work, but how does the second import account for any rows added by the application? You would have to manually map the id's or generate unique id's instead of having them increment.


Reply to this email directly or view it on GitHub: https://github.com/jdewit/AvroCsvBundle/pull/10#issuecomment-11915399

jp31415926 avatar Jan 05 '13 18:01 jp31415926

Let me just add that if the user does not annotate any fields as ImportIndex then the import works exactly as it did before.

jp31415926 avatar Jan 06 '13 03:01 jp31415926