Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.
/ postshift Public archive
forked from ValiMail/postshift

Amazon Redshift extension for ActiveRecord 5 (Rails 5) PostgreSQL adapter based off of the existing activerecord5-redshift-adapter.

License

Notifications You must be signed in to change notification settings

monsterstrike/postshift

 
 

Repository files navigation

Postshift

Amazon Redshift extension for ActiveRecord 5 (Rails 5) PostgreSQL adapter based off of the existing activerecord5-redshift-adapter. This version has 3 primary goals:

  1. Function as an extension of the PostgreSQL ActiveRecord adapter. Overriding or extending as needed to properly account for the differences between PostgreSQL and Redshift.
  2. Create a functioning test suite.
  3. Support the following versions of ActiveRecord:
    • 5.0
    • 5.1
    • 5.2

https://github.com/ConsultingMD/activerecord5-redshift-adapter

Installation

Add this line to your application's Gemfile:

gem 'postshift'

And then execute:

$ bundle

Or install it yourself as:

$ gem install postshift

In your Rails 5+ database.yml

development:
  adapter: redshift
  host: your_cluster_name.at.redshift.amazonaws.com
  port: 5439
  database: your_db
  username: your_user
  password: your_password
  encoding: utf8
  pool: 3
  timeout: 5000

Migrations

Postshift exposes Redshift table and column options within ActiveRecord migrations.

DISTKEY & SORTKEY Table Configuration

The DISTKEY and SORTKEY can be passed through the create_table syntax:

create_table 'example_table', distkey: 'name', sortkey: 'number' do |t|
	t.string :name
	t.integer :number
end

Column Compression Encoding

Redshift column compression encoding can be specified inline as an option within migrations:

create_table 'encoding_examples' do |t|
	t.integer :number, encoding: 'delta'
end

For more information on compression types: http://docs.aws.amazon.com/redshift/latest/dg/c_Compression_encodings.html

Schema Dump

Several Rake tasks exist to help with performing a schema dump of an existing Redshift database. These utilize the admin scripts provided by Amazon. All actions are performed using ActiveRecord::Base.connection by default.

These views must exist within the Redshift database under the admin schema prior to any dump or restore actions. To generate, simple run:

rake postshift:schema:prepare

Once these views are in place, the dump and restore will be available and functional.

rake postshift:schema:dump
rake postshift:schema:restore

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Testing

To run the full test suite, a functioning Redshift database instance is required. Once provisioned, copy the example configuration and update with your connection information & run the spec migrations:

cp spec/config.example.yml spec/config.yml

rake spec:db:migrate

And finally, you can now run the entire test suite:

rake spec

The spec structure is based on reliance of an available running Redshift instance. These specs can be run separately:

rake spec:isolated	# Run isolated non-Redshift reliant code examples
rake spec:redshift	# Run Redshift reliant code examples

Additionally, there is multi-version test support through Appraisal.

appraisal install
appraisal ar-5.0 rake spec
appraisal ar-5.1 rake spec
appraisal ar-5.2 rake spec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ValiMail/postshift. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

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

About

Amazon Redshift extension for ActiveRecord 5 (Rails 5) PostgreSQL adapter based off of the existing activerecord5-redshift-adapter.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 99.8%
  • Shell 0.2%