influitive / apartment

Database multi-tenancy for Rack (and Rails) applications
2.67k stars 460 forks source link

Rails 5.2.2 + Apartment 2.2.0 - Multi servers migrations not working. #596

Closed TheMasterCado closed 5 years ago

TheMasterCado commented 5 years ago

Steps to reproduce

Setup Apartment to use multiple servers and create a tenant in a distant server, not the one in database.yml. Add a migration and run rake db:migrate.

Expected behavior

Apartment connect to each tenant from their db_configuration and run the migrations on them.

Actual behavior

Apartment cannot find the distant schemas and migrate only the schema on the server specified in database.yml.

System configuration

Simple Linux Mint VM for development and a second VM to run a second PostgreSQL instance.

require 'apartment/elevators/subdomain'

#

Apartment Configuration

# Apartment.configure do |config| config.excluded_models = %w{ Tenant Delayed::Job } config.with_multi_server_setup = true

config.default_schema = "public" config.tenant_names = lambda do Tenant.all.each_with_object({}) do |tenant, hash| hash[tenant.subdomain] = tenant.db_configuration end end end

Rails.application.config.middleware.use Apartment::Elevators::Subdomain



* `use_schemas`: (`true` or `false`): true

* Rails (or ActiveRecord) version: 5.2.2

* Ruby version: 2.5.3

---

I may be missing some steps to get a working multi servers setup, but I've followed the little documentation on that. Thanks in advance.
TheMasterCado commented 5 years ago

@mikecmpbll I saw that you're now a collaborator (#591 ) for that project because you're a big user of it (your company). I'm in a similar situation here and wanted to see what your intentions are with it. Maybe your changes could help us with our problem or you may already know how to solve it. Thank you!

danmcquade commented 5 years ago

I was having a similar issue, and I found that 'use_schemas' had to be set to false in order for the multi server setup to work ('config.with_multi_server_setup = true').