Hi David,

I ran into this situation as well, and went with another solution. I don't 
want bad data in my new database, and the import process presents an 
opportunity to clean up the source database. So what I did is collect the 
records that fail validation in a Hash, then at the end of the import 
process, send the Hash to a Mailer class. The StaffMailer class sends an 
email to the staff who maintain the source database, and has a summary of 
records with missing/bad data, asking them to fix it. This way, the old 
(source) database gets cleaned up, and the new one never gets polluted with 
invalid records.

Cheers,
Brent


On Tuesday, October 13, 2015 at 2:30:14 PM UTC-6, David McDonald wrote:
>
> I'm currently trying to setup daily processes that will import information 
> into my database.  I have many records that fail validations, and for the 
> most part I have methods that attempt to auto-correct them and re-save, but 
> there are some more complex scenarios that require a user to correct some 
> information before they're valid.  I'm trying to come up with a good way in 
> which I can set this up and I've come up with two methods, but I'm not sure 
> which I should really go with...
>
> *Scenario 1:*
>
> I figure I could import into my models like I normally do, and when they 
> don't pass validations then I will go ahead and save them to the database 
> anyways and then flag them with a boolean column as "invalid".  Then I'll 
> setup an action and view to allow the user to see and correct all the 
> records that have been flagged.  
>
> *Pros:* The pro to this method is I don't have to create various new 
> models/tables for each model that I'm importing into for temporary storage.
> *Cons:* I'm still storing bad data in the table, and also would have to 
> alter many queries to filter out invalid records based on the boolean 
> column I would add to the model.
>
> *Scenario 2:*
>
> I create new models that mimic the model that I want to import the records 
> into... but then I'm adding alot of logic that is shared between the two -- 
> not to mention I have a lot of additional files and code.  However, this 
> method wouldn't have me storing invalid data in my tables.
>
>
> Thoughts?
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/b43c606e-fa48-497c-bf4c-5ce441c84c04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to