Schema Validations Plugin
By Simon HarrisAfter listening to Prag Dave’s Keynote Speech this afternoon, I was motivated to implement some of the things he’d been asking for. Here’s my first cut at it.
As the doco says, the plugin reads some – ok only one at the moment but we’ll see how many others I get done before the beer runs out – database column constraints and tries to apply the closest corresponding rails validation. The first one I implemented reads the NOT NULL constraints against columns and generates a corresponding validates_presence_of.
I literally just whipped it up with no tests or what-not and I’ve only played with it against PostgreSQL, so if it has bugs or behaves oddly for whatever reason, please let me know, send me as much info as possible and I’ll make it work. Nothing better than having real people testing it for me ;-)
UPDATE: OK, so far the beer has lasted long enough to implement validation of numbers (including specific support for integers) and lengths of strings.
UPDATE: Now calls validates_presence_of anytime you declare a belongs_to association for a NOT NULL foreign-key column.
UPDATE: Single-column unique indexes are now converted to validates_uniqueness_of.