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

Is it possible to use the Apartment gem WITHOUT rails? #602

Open
gmhawash opened this issue Apr 30, 2019 · 6 comments
Open

Is it possible to use the Apartment gem WITHOUT rails? #602

gmhawash opened this issue Apr 30, 2019 · 6 comments

Comments

@gmhawash
Copy link

gmhawash commented Apr 30, 2019

Hello,

I have a multi-tenant PG application that uses standalone ruby workers to access the database. I'd like to be able to use the Apartment gem to create schemas and switch to schemas from these standalone workers. How is this possible?

Thanks

@tachyons
Copy link
Contributor

tachyons commented May 6, 2019

Difficult in current architecture as apartment relays on ActiveRecord

@mikecmpbll
Copy link
Collaborator

it requires activerecord

@gmhawash
Copy link
Author

gmhawash commented Jun 4, 2019

Active record is fine, but in the file https://github.com/influitive/apartment/blob/a4332c3222210b11f5e8c27fa4c1a18b492e9629/lib/apartment/adapters/abstract_adapter.rb, in the environmentify method, you refer to Rails.env which forces a dependency on Rails which is not necessary for this gem.

@mikecmpbll mikecmpbll reopened this Jun 4, 2019
@mikecmpbll
Copy link
Collaborator

gotcha, thanks

@arinhouck
Copy link

@gmhawash Did you work out a solution to get the gem to work within a ruby project?

@gmhawash
Copy link
Author

gmhawash commented Nov 5, 2019

@arinhouck I did not, but I avoid using create_tenant_command, and it is not necessary for Postgresql. If you must, you could define a module in an initialization file as follows:

module Rails
  module_function :env
  def env
     ENV['RACK_ENV']  # or whatever you use to declare an env.
  end
end 

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

4 participants