GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: A clean way to add constraints to your PostgreSQL database.
Clone URL: git://github.com/fesplugas/simplified_constraints.git
fesplugas (author)
Fri Oct 03 06:51:09 -0700 2008
commit  0b38e412f19c32bbbe258c38272a675a901e90da
tree    e14480a1175f5ca76d7c2e567351dc31862db9a4
parent  357b61aeb317c0346ffaa715d3ad6fe5de5065a8
name age message
file MIT-LICENSE Mon May 26 23:59:27 -0700 2008 9:00am commit ... [fesplugas]
file README Sat Jun 28 14:33:36 -0700 2008 Updated README with instruction on how to test [fesplugas]
file Rakefile Mon May 26 23:59:27 -0700 2008 9:00am commit ... [fesplugas]
file init.rb Mon May 26 23:59:27 -0700 2008 9:00am commit ... [fesplugas]
directory lib/ Fri Oct 03 06:51:09 -0700 2008 Removed old code [fesplugas]
directory test/ Sat Jun 28 14:33:01 -0700 2008 Tip#1: Never use code without tests [fesplugas]
README
== Simplified Constraints

Because adding database constraints should be easy.

Available constraints:

* Email: Validates format of email
* Login: Validates uniqueness of login names
* Positive: Validates positiveness of a number
* Length: Validates length of a value
* Uniqueness

<b>Note:</b> Only works on PostgreSQL. This is an initial work. And I've planned
to add the common Rails validations +validates_format_of+, +validates_inclusion_of+, 
+validates_lenght_of+, +validates_numericality_of+, +validates_size_of+, 
+validates_uniqueness_of+.

== Example

    class AddConstraintsOnModels < ActiveRecord::Migration

      def self.up
        add_email_check :users, :email
        add_login_check :users, :login
        add_positive_check :products, :price
        add_length_check :users, :login, :is => 8
        add_uniqueness_check :user, :login
      end

      def self.down
        remove_email_check :users, :email
        remove_login_check :users, :login
        remove_positive_check :users, :price
        remove_length_check :users, :login, :is => 8
        remove_uniqueness_check :user, :login
      end

    end

== How to test?

    $ createdb simplified_constraints
    $ rake

Copyright (c) 2008 Francesc Esplugas Marti, released under the MIT license