SchemaPlus::PgTypes
SchemaPlus::PgTypes adds better support for PostgreSQL-specific types to
ActiveRecord, mapping them to higher-level types instead of raw strings.
Currently this only includes the PostgreSQL interval type, which is mapped
to ActiveSupport::Duration.
Installation
As usual:
gem "schema_plus_pg_types" # in a Gemfile
gem.add_dependency "schema_plus_pg_types" # in a .gemspecCompatibility
SchemaPlus::PgTypes is tested on:
- ruby 2.3.1 with activerecord 5.0, using postgresql
Usage
This gem adds a little more syntactic sugar for defining PostgreSQL types in your migrations. You can now simply write:
create_table :events do |t|
t.interval :event_duration
endInstead of:
create_table :events do |t|
t.column :event_duration, :interval
endThe event_duration column will be represented as ActiveSupport::Duration
in your model, so you should be able to use it without the usual fuss:
long_events = Event.where(1.hours..10.hours)SchemaPlus::PgTypes is part of the SchemaPlus family of Ruby on Rails ActiveRecord extension gems.
History
- 0.1.1 - Improve test coverage (no change to production code)
- 0.1.0 - Initial release
Development & Testing
Are you interested in contributing to SchemaPlus::PgTypes? Thanks! Please follow the standard protocol: fork, feature branch, develop, push, and issue pull request.
Some things to know about to help you develop and test:
-
schema_dev: SchemaPlus::PgTypes uses schema_dev to facilitate running rspec tests on the matrix of ruby, activerecord, and database versions that the gem supports, both locally and on travis-ci
To to run rspec locally on the full matrix, do:
$ schema_dev bundle install $ schema_dev rspecYou can also run on just one configuration at a time; For info, see
schema_dev --helpor the schema_dev README.The matrix of configurations is specified in
schema_dev.ymlin the project root.
- schema_plus_core: SchemaPlus::PgTypes uses the SchemaPlus::Core API that provides middleware callback stacks to make it easy to extend ActiveRecord's behavior. If that API is missing something you need for your contribution, please head over to schema_plus_core and open an issue or pull request.
- schema_monkey: SchemaPlus::PgTypes is implemented as a schema_monkey client, using schema_monkey's convention-based protocols for extending ActiveRecord and using middleware stacks.