Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rails plugin that allows creation and management of database constraints such as uniqueness and referential integrity (foreign keys) using ActiveRecord Migrations. (Originally written by Alistair A. Israel)
Ruby
Branch: master
Pull request Compare This branch is 1 commit ahead of jlw:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
LICENSE
README
Rakefile
init.rb

README

# Migrations Constraints

MigrationsConstraints adds the capability to add/drop table constraints or 
specify column constraints during table creation time to 
ActiveRecord::Migrations.

It currently supports the following:

  create_table :users do |t|
    t.column :login, :string, :limit => 20, :null => false, :unique => true
    t.column :type, :string, :limit => 80, :null => false
  end
    
  create_table :projects do |t|
    t.column :owner_id, :integer, :null => false, :references => :users
    t.column :name, :string, :null => false
  end
  
  create_table :line_items do |t|
    t.column :quantity, :integer, :null => false, :check => '> 0'
  end
  
  add_constraint :projects, :unique => :name
  drop_constraint :projects, :unique => :name
  
  add_constraint :project_members, :foreign_key => :project_id, :references => :projects
  add_constraint :project_members, :foreign_key => :user_id, :references => :users
  
  drop_constraint :project_members, :foreign_key => :user_id, :references => :users
  drop_constraint :project_members, :foreign_key => :project_id, :references => :projects
  
  add_constraint :line_items, :name => 'line_items_max_quantity_check', :check => 'quantity < 10000'
  drop_constraint :line_items, :name => 'line_items_max_quantity_check'

## Constraint Naming

Constraints by default are named according to the default naming convention used
by PostgreSQL 8.2.x. That is for a given table +table+, column +column+:

* A unique constraint is named +table_column_uq+.
* A foreign key constraint is named +table_column_fkey+.
* A check constraint is named +table_column_check+.

Otherwise, a constraint's name can be specified explicitly via the +:name+
parameter:

  add_constraint :books, :foreign_key => :author_id, :references => :authors, :name => 'books_authors_fkey'

## Release Notes

MigrationsConstraints is currently being developed and tested using a PostgreSQL
8.2 database back-end.

If the database you're using doesn't follow the same (ANSI SQL 92) data
definition language for specifying database constraints, then please support
this project by contributing to the code. :)

## History

[Alistair A. Israel](http://alistairisrael.wordpress.com/) created this plugin in 2007 ([see the RubyForge project](http://rubyforge.org/projects/mig-constraints/)).
Something went wrong with that request. Please try again.