Patrick Doyle wrote:
> Suppose one had a hypothetical situation in which records were entered 
> into
> a database which were later determined to be invalid.

Because they were invalid in the first place, or because the criteria 
for validity changed?

> 
> In this supposedly hypothetical situation, the agile programmer might 
> add
> validations to the models to ensure this doesn't, err, wouldn't happen
> again.

Yes.  And also constraints in the database.

> 
> Following that, there might be some records in the database which were
> invalid.
> 
> I like thinking about hypothetical questions and coming up with 
> hypothetical
> answers, and I thought that perhaps there might be other readers on this
> list who enjoy that sort of game too.  So, for those of you who enjoy 
> that
> sort of thing, what would you do to address this?
> 
> One thing I've thought of would be to write a throwaway rake task to 
> iterate
> through the items in the the affected table(s), calling the validate
> function on each one and reporting the results back.  If there were only 
> a
> few invalid records, I could probably go in and fix them by hand.  If 
> there
> were too many, I might write another rake task to identify and fix them.
> 

This seems quite reasonable.  If it's a question of the data structure 
changing and affecting validity, then it's probably a good idea to put 
the validation routine right in the migration file.

> If I did that, would I really "throwaway" the rake task when I was done?
> Probably not... I'd probably check it into source control and keep it 
> just
> for documentation/history's sake.

Right.

> 
> What would you do?

Remember to put checks in the DB wherever possible.  Rails validations 
are not a replacement for that.

> 
> --wpd

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to