GithubHelp home page GithubHelp logo

storey's Introduction

Storey

Storey is used to manage multiple schemas in your multi-tenant Rails application.

Heavily inspired by the Apartment gem, Storey simplifies the implementation of managing a multi-tenant application. This simplifies things by doing away with the other implementations that Apartment has - like MysqlAdapter and managing multiple databases (instead of managing multiple schemas) which complicated development and testing.

Configuration

Typically set in an initializer: config/initializer/storey.rb

# Defines the tables that should stay available to all (ie in the public schema)
# Note that there's currently no way to exclude tables that aren't linked to models
# If you have any ideas on how to do this I'm open to suggestions
Storey.excluded_models = %w(User Company Role Permission)

# If set, all schemas are created with the suffix.
# Used for obscuring the schema name - which is important when performing schema duplication.
# Storey.suffix = "_suffix"

# Defines schemas that should always stay in the search path, apart from the one you switched to.
# Storey.persistent_schemas = %w(hstore)

Methods

schemas

Returns all schemas except postgres' schemas.

Accepts options:

:exclude_public => true

Usage:

Storey.schemas
Storey.schemas(:exclude_public => true)

default_schema?

Returns true if the current schema is the default schema. Returns false otherwise. Useful for running migrations only for the public schema.

Usage:

Storey.default_schema?

create

Accepts:

String - name of schema

Usage:

Storey.create "schema_name"

drop

Accepts

String - name of schema

Usage:

Storey.drop "schema_name"

switch

Accepts

String - optional - schema name
Block - optional

If a block is passed, Storey will execute the block in the specified schema name. Then, it will switch back to the schema it was previously in.

Usage:

Storey.switch "some_other_schema"
Post.create "My new post"
Storey.switch # switch back to the original schema

Storey.switch "some_other_schema" do
  Post.create "My new post"
end

duplicate!(origin, copy)

Accepts

origin - name of old schema to copy
copy - name of new schema

Copies a schema with all data under a new name. Best used in conjunction with Storey.suffix set.

Usage:

Storey.duplicate!("original_schema", "new_schema")

Rake tasks

storey:hstore:install

Run rake storey:hstore:install to install hstore extension into the hstore schema. Ensure that 'hstore' is one of the persistent schemas.

storey's People

Contributors

ramontayag avatar

Watchers

 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.