README.md in apartment-0.16.0 vs README.md in apartment-0.17.0

- old
+ new

@@ -1,6 +1,9 @@ # Apartment +[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/influitive/apartment) +[![Build Status](https://secure.travis-ci.org/influitive/apartment.png?branch=development)](http://travis-ci.org/influitive/apartment) + *Multitenancy for Rails 3 and ActiveRecord* Apartment provides tools to help you deal with multiple databases in your Rails application. If you need to have certain data sequestered based on account or company, but still allow some data to exist in a common database, Apartment can help. @@ -127,18 +130,35 @@ **Persistent Schemas** Apartment will normally just switch the `schema_search_path` whole hog to the one passed in. This can lead to problems if you want other schemas to always be searched as well. Enter `persistent_schemas`. You can configure a list of other schemas that will always remain in the search path, while the default gets swapped out: config.persistent_schemas = ['some', 'other', 'schemas'] -This has numerous useful applications. [Hstore](http://www.postgresql.org/docs/9.1/static/hstore.html), for instance, is a popular storage engine for Postgresql. In order to use Hstore, you have to install to a specific schema and have that always in the `schema_search_path`. This could be achieved like so: +This has numerous useful applications. [Hstore](http://www.postgresql.org/docs/9.1/static/hstore.html), for instance, is a popular storage engine for Postgresql. In order to use Hstore, you have to install it to a specific schema and have that always in the `schema_search_path`. This could be achieved like so: + # NOTE do not do this in a migration, must be done + # manually before you configure apartment with hstore # In a rake task, or on the console... ActiveRecord::Base.connection.execute("CREATE SCHEMA hstore; CREATE EXTENSION HSTORE SCHEMA hstore") # configure Apartment to maintain the `hstore` schema in the `schema_search_path` config.persistent_schemas = ['hstore'] +There are a few caveats to be aware of when using `hstore`. First off, the hstore schema and extension creation need to be done manually *before* you reference it in any way in your migrations, database.yml or apartment. This is an unfortunate manual step, but I haven't found a way around it. You can achieve this from the command line using something like: + + rails r 'ActiveRecord::Base.connection.execute("CREATE SCHEMA hstore; CREATE EXTENSION HSTORE SCHEMA hstore")' + +Next, your `database.yml` file must mimic what you've set for your default and persistent schemas in Apartment. When you run migrataions with Rails, it won't know about the hstore schema because Apartment isn't injected into the default connection, it's done on a per-request basis, therefore Rails doesn't know about `hstore` during migrations. To do so, add the following to your `database.yml` for all environments + + # database.yml + ... + adapter: postgresql + schema_search_path: "public,hstore" + ... + +This would be for a config with `default_schema` set to `public` and `persistent_schemas` set to `['hstore']` + + ### Managing Migrations In order to migrate all of your databases (or posgresql schemas) you need to provide a list of dbs to Apartment. You can make this dynamic by providing a Proc object to be called on migrations. This object should yield an array of string representing each database name. Example: @@ -203,9 +223,11 @@ config.excluded_models = ["Delayed::Job"] ## Development -* The Local setup for development assumes that a root user with no password exists for both mysql and postgresl +* In both `spec/dummy/config` and `spec/config`, you will see `database.yml.sample` files + * Copy them into the same directory but with the name `database.yml` + * Edit them to fit your own settings * Rake tasks (see the Rakefile) will help you setup your dbs necessary to run tests * Please issue pull requests to the `development` branch. All development happens here, master is used for releases -* Ensure that your code is accompanied with tests. No code will be merged without tests \ No newline at end of file +* Ensure that your code is accompanied with tests. No code will be merged without tests