0.0
No release in over a year
A Ruby helper library for applications using Reshape
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.5.3

Runtime

~> 0.3.0
~> 0.3.0
 Project Readme

Reshape Ruby helper

Tests

This is a Ruby helper library for the automated, zero-downtime schema migration tool Reshape. To achieve zero-downtime migrations, Reshape requires that your application runs a simple query when it opens a connection to the database to select the right schema. This library automates that process with a simple method which will return the correct query for your application. It also works great with Rails!

Installation

Add reshape_helper as a dependency to your Gemfile:

gem "reshape_helper", "~> 0.2.1"

Usage

The library includes a ReshapeHelper::schema_query method which will find all your Reshape migration files and determine the right schema query to run. Here's an example of how to use it:

require "reshape_helper"

schema_query = ReshapeHelper::schema_query

# Run the schema query against your database when you open a new connection
db.execute(schema_query)

By default, ReshapeHelper::schema_query will look for migrations files in migrations/ but you can specify your own directories as well:

require "reshape_helper"

schema_query = ReshapeHelper::schema_query(
	"src/users/migrations",
	"src/todos/migrations",
)

Usage with Rails

Using Reshape for zero-downtime migrations with Ruby on Rails is dead simple. After adding reshape_helper to your Gemfile, update config/database.yml and add a schema_search_path setting like this:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  schema_search_path: <%= ReshapeHelper::search_path %>

Now your Rails app is ready for use with Reshape. Rather than creating standard Active Record migrations using bin/rails generate migration ..., you should create Reshape migration files in migrations/. If you'd prefer to use other folders for your migrations, you can pass them along as arguments:

schema_search_path: <%= ReshapeHelper.search_path("src/users/migrations", "src/todos/migrations") %>

License

Released under the MIT license.