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

Incompatible with Postgresql 11.1 #571

Open
ArnisL opened this issue Nov 20, 2018 · 4 comments
Open

Incompatible with Postgresql 11.1 #571

ArnisL opened this issue Nov 20, 2018 · 4 comments

Comments

@ArnisL
Copy link

ArnisL commented Nov 20, 2018

Steps to reproduce

Apartment::Tenant.create('test')

Expected behavior

create a new tenant named test

Actual behavior

apparently "forgets" the name and tries to create another "public" schema

System configuration

arch linux something

  • Database: (Tell us what database and its version you use.)
    Postgresql 11.1

  • Apartment version:
    2.2.0

  • Apartment config (in config/initializers/apartment.rb or so):

require 'middleware/my_elevator'

#
# Apartment Configuration
#
Apartment.configure do |config|

  # Exclude the following models from the tenant.
  config.excluded_models = %w(Subdomain SubdomainUser Permission User OnlineUser)

  # Use postgres schemas
  config.use_schemas = true

  # Ensure the seeds.rb file is run when a tenant is created.
  config.seed_after_create = true

  # The list of tenants is driven from the subdomain model, based on sub domain.
  config.tenant_names = lambda { Subdomain.pluck :subdomain }

  # Use the SQL generation for the schemas, rather than schema.rb
  config.use_sql = true

end

# Switch the apartment based on sub domain.
Rails.application.config.middleware.use MyElevator
  • use_schemas: (true or false)
    true

  • Rails (or ActiveRecord) version:
    5.0.6

  • Ruby version:
    2.3.3

@toao
Copy link

toao commented Jan 10, 2019

Same issue with Rails 5.2.2 and Ruby 2.5.3

@tappleby
Copy link

It seems like newer versions of pg_dump will always include CREATE SCHEMA public; if specifying a schema on the command line.

I ran into something similar while working on an external application for provisioning tenants where create schema command would be included for non public schemas, I ended up replacing the create schema calls in swap_schema_qualifier

new_sql.gsub!(/CREATE SCHEMA #{@source_schema}\;/, '')

I could be worth adding CREATE SCHEMA to the pg dump block list, but there might be some setups where creating more then one schema per tenant is a valid use case?

PSQL_DUMP_BLACKLISTED_STATEMENTS= [
/SET search_path/i, # overridden later
/SET lock_timeout/i, # new in postgresql 9.3
/SET row_security/i, # new in postgresql 9.5
/SET idle_in_transaction_session_timeout/i, # new in postgresql 9.6
]

@toao
Copy link

toao commented Mar 21, 2019

@tappleby thanks for your feedback, I just used the latter approach for a lokal money patch.

@toao
Copy link

toao commented Jun 28, 2019

does 927ba21 wich is included in v2.2.1 fixes this finally?

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

3 participants