This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Francesc Esplugas (author)
Sat Apr 25 03:26:57 -0700 2009
commit 0fff5b6940c9f01fbadbfa4a09ed491e17af70de
tree 40030765286d47ebf9d959475edfbdad367e434b
parent 19ef636d880c339609a3bb8cb918abc7ed1f150d
tree 40030765286d47ebf9d959475edfbdad367e434b
parent 19ef636d880c339609a3bb8cb918abc7ed1f150d
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Tue Apr 21 02:26:34 -0700 2009 | |
| |
README.rdoc | Sat Apr 25 03:17:01 -0700 2009 | |
| |
Rakefile | Sat Apr 25 01:04:14 -0700 2009 | |
| |
generators/ | Sat Apr 25 03:26:57 -0700 2009 | |
| |
init.rb | Sat Apr 25 02:39:58 -0700 2009 | |
| |
lib/ | Sat Apr 25 03:13:20 -0700 2009 | |
| |
test/ | Sat Apr 25 03:13:20 -0700 2009 |
README.rdoc
Database Constraints
Adding database constraints to PostgreSQL the Rails way.
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
- Foreign keys
Example
Foreign keys:
class AddForeignKeysToModels < ActiveRecord::Migration
def self.up
# add_foreign_key :from_table, :from_column, :to_table
add_foreign_key :articles, :user_id, :users
end
def self.down
# remove_foreign_key :from_table, :from_column
remove_foreign_key :articles, :user_id
end
end
Validations:
class AddConstraintsToModels < 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?
Create a PostgreSQL database named database_constraints and run rake.
Copyright © 2008-2009 Francesc Esplugas Marti, released under the MIT license







