influitive / apartment

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

sqlserver adapter is not supported #574

Open vinaymehta opened 5 years ago

vinaymehta commented 5 years ago

This gem doesn't support sqlserver adapter.

clintmiller commented 5 years ago

We've added this support: https://github.com/rtcreativegroup/apartment/tree/crashdown-rails-5. I wouldn't consider it release-ready, but we use it in production, and you shouldn't have too much difficulty if you are familiar with the inner-workings of Apartment.

vinaymehta commented 5 years ago

Though I am now able to install apartment in my application. But I am still having issues while creating tenants using apartment. It gives errors like NoMethodError: undefined method `name' for #<ActiveSupport::HashWithIndifferentAccess in ruby-2.3.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:849:in `establish_connection'

I checked the file and found the error is in calling methods like spec.name or spec.config etc. in the connection_pool.rb file. I print my spec and it comes like {"adapter"=>"sqlserver", "mode"=>"dblib", "host"=>"MYHost", "port"=>Port, "database"=>"MYDB", "username"=>"USERNAME", "password"=>"PASSWORD", "timeout"=>50000000, "azure"=>true, "name"=>"NAME"}. I tried to add condition on this line if the class of spec is HashwithIndifferentAccess then use values like spec["name"] But then it started giving errors in other lines like NoMethodError: undefined method `config' for #

Is it because of sqlserver adapter?

clintmiller commented 5 years ago

Our fork of Apartment currently targets Rails 5.1. It doesn't seem like the connection pool class is doing anything that different when it's getting the spec's name & config, but I wonder if something related to the way the config/database.yml file is loaded or represented in memory has changed.

vinaymehta commented 5 years ago

So Is there any way to get the reason of the error? I also feel that the database.yml file is loaded differently in memory. Is it because of sqlserver or rails 5?

My System Configuration ruby 2.3.1p112 Rails 5.0.6 apartment (1.2.0)

Apartment config (in config/initializers/apartment.rb or so): use_schemas: (true or false) (tried both)

clintmiller commented 5 years ago

Did you add our fork of this gem to your Gemfile? Did you the specific branch I referenced? When we add it to our apps, we use

gem 'apartment', git: 'https://github.com/rtcreativegroup/apartment', branch: 'crashdown-rails-5'