discourse/rails_multisite

Name: rails_multisite

Owner: Discourse

Description: Multi tenancy for Rails applications

Created: 2015-10-12 03:39:28.0

Updated: 2018-04-13 14:30:23.0

Pushed: 2018-02-12 07:40:15.0

Homepage: null

Size: 52

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Rails Multisite

This gem provides multi-db support for Rails applications.

Using its middleware you can partition your app so each hostname has its own db.

It provides a series of helper for working with multiple database, and some additional rails tasks for working with them.

It was extracted from Discourse. https://discourse.org

Installation

Add this line to your application's Gemfile:

gem 'rails_multisite'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails_multisite
Usage

Configuration requires a file called: config/multisite.yml that specifies connection specs for all dbs.


apter: postgresql
tabase: discourse_mlp
ername: discourse_mlp
ssword: applejack
st: dbhost
ol: 5
meout: 5000
_id: 1  # ensure db_id is unique for each site
st_names:
- discourse.equestria.com
- discourse.equestria.internal

o:
apter: postgresql
tabase: discourse_who
ername: discourse_who
ssword: "Up the time stream without a TARDIS"
st: dbhost
ol: 5
meout: 5000
_id: 2 # ensure db_id is unique for each site
st_names:
- discuss.tardis.gallifrey
Execute a query on each connection
sMultisite::ConnectionManagement.each_connection do |db|
run query in context of db
eg: User.find(1)


sMultisite::ConnectionManagement.each_connection(threads: 5) do |db|
run query in context of db, will do so in a thread pool of 5 threads
if any query fails an exception will be raised
eg: User.find(1)

Contributing
  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.