Code Monkey home page Code Monkey logo

postshift's Introduction

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
    • 6.0

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
appraisal ar-6.0rc2 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.

postshift's People

Contributors

davekrupinski avatar petergoldstein avatar dweinand avatar pccowboy avatar

Stargazers

Joshua Sayavong avatar Saul Fuhrmann 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.