Open nynhex opened 6 years ago
how're you switching?
In the application controller, in a before_action like so:
before_action :load_schema, :authenticate_user!
private
def load_schema
Apartment::Tenant.switch!('public')
return unless request.subdomain.present?
if current_account
Apartment::Tenant.switch!(current_account.subdomain)
else
redirect_to root_url(subdomain: false)
end
end
Note, this worked before, but perhaps I don't have a public schema in postgres? This is a new machine.
looks like 'tenant', here https://github.com/influitive/apartment/blob/development/lib/apartment/adapters/postgresql_adapter.rb#L79, is an empty string, judging from the error message.
could current_account.subdomain
be returning an empty string? debug along those lines and you should be able to get to the bottom of it.
@mikecmpbll Thanks for the dig on this Mike. I'll take a look at it today. I just bootstrapped the app on my laptop a while back so right now there's no account objects or anything seeded. But IIRC when I was working on this in the past I didn't require an account to be there. It just switched to the public schema. I'll post my findings hopefully today so we can close this out. 👍
@nynhex / @mikecmpbll were you able to figure this out ? I'm running into the same error while deploying to AWS using Elastic Beanstalk. In the browser, I receive the "We're sorry, but something went wrong." page ... but looking at the logs, I see this error: Apartment::TenantNotFound (One of the following schema(s) is invalid: "ata-prod" "public", "shared_extensions")
I'm stuck on this issue and any help would be appreciated ...
I am also running into this problem - anyone figure out the issue?
I ran into to this today after I mucked around with a few things in my environment. I could switch in the console, but not via http requests. By chance, I ran db:migrate
and saw that some of the tenants were missing migrations in their "schema_migrations" table. However, the tenants did have the tables referenced in the migrations. So real dirty, in the console I did the following (note: TourSet
is my class for tenants):
schemas = ActiveRecord::SchemaMigration.all
TourSet.all.each do |ts|
Apartment::Tenant.switch!(ts.subdir)
schemas.each do |schema|
migration = ActiveRecord::SchemaMigration.find_by_version(schema.version)
if migration.nil?
ActiveRecord::SchemaMigration.create(version: schema.version)
end
end
end
I'm not proud, but it worked for me. Maybe some of y'all have similar issues. ¯_(ツ)_/¯
I am having the same, if not a similar issue. All migrations run against the 'public' schema without issues, so to do the seeds (using seed_fu). But, when Apartment tries to create the schemas for each of the tenants I get the following error.
rake db:migrate
I have tried running migrate against PGv11, PGv10, and PGv9 and I get the same error.
Gem Versions: Ruby 2.6.1 Rails 5.2.2 pg 1.1.4 or 0.21.0 (tried both) apartment 2.2.0
Apartment Config: Subdomain config.excluded_models = %w{ Clinic } config.tenant_names = ['zenith', 'myotherapy'] (everything else left at defaults)
Application Config: Subdomain config.middleware.use Apartment::Elevators::Subdomain
I ran into the same issue, and here's how I fixed it
I simply added an after_create
callback called create_tenant
to the model of the subdomain for my multi-tenant, which is user.rb
in app/models/user.rb
Find below a link on Stackoverflow for the detailed answer https://stackoverflow.com/a/57771338/10907864
I had the same issue and I solved it by:
sudo -u postgres psql
\c databasename;
(to view all existing databases, run: \l+
)\dn+;
ALTER SCHEMA old_name RENAME TO new_name
After this, everything got back to normal.
I'm working on an app for my company with Rails 5.1.5, Ruby 2.5.0, and Apartment latest gem cut 2.1
I haven't worked on this app for 6 months. And even before I upgraded to 5.1.5/2.5.0 I was on Rails 5.0.1 and Ruby 2.4.0 and received this error. just stalled the project and never got around to revisiting it.
There was an exception - Apartment::TenantNotFound(One of the following schema(s) is invalid: "" "public")
I'm using Postgres, for what it's worth.
I've dropped the database, recreated it, ran the migrations which did not error out. Yet when I start the rails server I get the following exception/stacktrace:
Database: psql (PostgreSQL) 10.1 MacOS High Sierra installed through homebrew
Apartment version: 2.1
Apartment config (in
config/initializers/apartment.rb
or so):use_schemas
:trueAny help you can provide is greatly appreciated.