Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change table name in apartment.rb #437

Closed
laerciocrestani opened this issue Jun 14, 2017 · 6 comments
Closed

Change table name in apartment.rb #437

laerciocrestani opened this issue Jun 14, 2017 · 6 comments
Assignees

Comments

@laerciocrestani
Copy link

Hello.
captura de tela 2017-06-14 as 15 33 56
captura de tela 2017-06-14 as 15 33 50

My question would be:
Today I have the following tanant:
Subdomain: itsmileacademia.pidia.com.br
Database I need connection: itsmileacademi (without the "a")
But I can not set the database in config.tenant_names

Notice that it searches the database for the subdomain and I have this for many clients, however I now have an external connection to another HOST and they can not rename the base.

Look at the attachments.

Someone could help me how I should proceed. Thank you very much.

@mikecmpbll
Copy link
Collaborator

thanks for the report, i'll be looking into this over the coming days

@mikecmpbll mikecmpbll self-assigned this Jun 15, 2017
@mikecmpbll
Copy link
Collaborator

i think i'll be focusing on the rewrite of connection switching that i'm working on atm in #438 . you should be able to hack around this for now by calling your tenant "itsmileacademi" and then handling translating this specific case in your subdomain elevator.

i'd be happy to review an MR though.

@laerciocrestani
Copy link
Author

@mikecmpbll
I did not understand how I should do to be able to suppress it.
Can you kindly give me an example?
Tanks

@mikecmpbll
Copy link
Collaborator

mikecmpbll commented Jun 19, 2017

presumably you're using some kind of subdomain elevator? maybe the one that ships with apartment? that elevator would take the subdomain 'itsmileacademia', and try to connect to tenant 'itsmileacademia'. the problem is, the hash configuration overrides the database name with the tenant name, so if your database is really called 'itsmileacademi' that's what your tenant will have to be called.

sooo.. with that said, you can change your tenant names config to have 'itsmileacademi' as the tenant name, then you can write your own apartment connection middleware which is the same as what you're currently using, but which has something like:

subdomain = 'itsmileacademi' if subdomain == 'itsmileacademia'

# apartment will then connect to tenant 'itsmileacademi'

@laerciocrestani
Copy link
Author

@mikecmpbll
Sorry for my ignorance, but I saw here about the generic elevator, but when I tribute it I lose the subdomain, see below if I should use it this way?

Rails.application.config.middleware.use 'SiteBake::SiteElevator'
require 'apartment/elevators/generic'
module SiteBake
  # SiteBake::SiteElevator
  class SiteElevator < Apartment::Elevators::Generic
    def parse_tenant_name(request)
      domain = Domain.find_by_host request.host

      return domain.site.token unless domain.nil?

      fail StandardError, "Domain with host #{request.host} not found"
    end
  end
end

@mikecmpbll
Copy link
Collaborator

no problem! i suggest subclassing the subdomain elevator if that's what you need: https://github.com/influitive/apartment/blob/development/lib/apartment/elevators/subdomain.rb

you can then override parse_tenant_name with your custom behaviour.

if you have other questions you can find me at #apartment irc on freenode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants