Giter VIP home page Giter VIP logo

active_record-postgres-constraints's Introduction

Gem Version Build Status

ActiveRecord::Postgres::Constraints

From http://edgeguides.rubyonrails.org/active_record_migrations.html#types-of-schema-dumps:

There is however a trade-off: db/schema.rb cannot express database specific items such as triggers, stored procedures or check constraints. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to :sql.

No longer is this the case. You can now use the default schema format (:ruby) and still preserve your check constraints.

At this time, this only supports check constraints for the postgresql ActiveRecord database adapter.

Usage

Add a check constraint

Add check constraints to a table in a migration:

create_table :people do |t|
  t.string :title
  t.check_constraint title: ['Mr.', 'Mrs.', 'Dr.']
end

OR

add_check_constraint :people, title: ['Mr.', 'Mrs.', 'Dr.']

Remove a check constraint

# If you don't need it to be reversible:
remove_check_constraint :people

# If you need it to be reversible (Recommended):
remove_check_constraint :people, title: ['Mr.', 'Mrs.', 'Dr.']

Installation

Add this line to your application's Gemfile:

gem 'active_record-postgres-constraints'

And then execute:

$ bundle

Testing

$ (cd spec/dummy && bin/rake db:create RAILS_ENV=test) # One time before running tests
$ bundle exec rspec # To run tests as often as you'd like

Contributing

If you're interested in building support for other database adapters, we welcome your contribution!

License

The gem is available as open source under the terms of the MIT License.

active_record-postgres-constraints's People

Contributors

betesh avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.