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

Can't seed data in public schema with Rails 5.2 #531

Open
archonic opened this issue Mar 6, 2018 · 0 comments
Open

Can't seed data in public schema with Rails 5.2 #531

archonic opened this issue Mar 6, 2018 · 0 comments

Comments

@archonic
Copy link

archonic commented Mar 6, 2018

Steps to reproduce

Have a Rails 5.2.0.rc1 app with apartment installed and an excluded model Plan. Try to create plans in seeds.rb.

Expected behavior

Plans are created in the public schema.

Actual behavior

ERROR: relation "public.plans" does not exist

System configuration

  • Database: (Tell us what database and its version you use.)
    Postgres with use_schemas. Using docker and codeship. Image is postgres:10-alpine.

  • Apartment version:
    2.1.0. I'm using a fork to get around issue db:create fails #518.

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

    • use_schemas: (true or false)
      true
# Apartment Configuration
Apartment.configure do |config|

  # Add any models that you do not want to be multi-tenanted, but remain in the global (public) namespace.
  # A typical example would be a Customer or Tenant model that stores each Tenant's information.
  config.excluded_models = %w(
    Account
    User
    AccountsUser
    Plan
  )
  config.use_schemas = true
end

Rails.application.config.middleware.use Apartment::Elevators::Subdomain
  • Rails (or ActiveRecord) version:
    5.2.0.rc1

  • Ruby version:
    2.5

Full app is here:
https://github.com/archonic/limestone-accounts

This is my seeds.rb:

if Apartment::Tenant.current == 'public'
  plans = Plan.create([
    {name: 'Basic', amount: 900, currency: 'usd', interval: 'month', active: true},
    {name: 'Pro', amount: 1500, currency: 'usd', interval: 'month', active: true}
  ])
  puts "CREATED PLANS #{plans.pluck(:name).join(', ')}"

  accounts = Account.create([
    {name: 'Limestone', subdomain: 'limestone', plan_id: Plan.last.id, current_period_end: 5.years.from_now, trialing: false, past_due: false, unpaid: false, cancelled: false}
  ])
  puts "CREATES ACCOUNTS #{accounts.pluck(:name).join(', ')}"
end

if Apartment::Tenant.current == 'limestone'
  admin_user = CreateAdminService.call
  puts 'CREATED ADMIN USER: ' << admin_user.email
end

Backtrace:

Caused by:
(service: web) (step: rspec) PG::UndefinedTable: ERROR:  relation "public.plans" does not exist
LINE 8:                WHERE a.attrelid = '"public"."plans"'::regcla...
                                          ^
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `async_exec'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `block (2 levels) in query'
/usr/local/bundle/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/usr/local/bundle/gems/activesupport-5.2.0.rc1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/usr/local/bundle/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:62:in `block in query'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:579:in `block (2 levels) in log'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:578:in `block in log'
/usr/local/bundle/gems/activesupport-5.2.0.rc1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:569:in `log'
(service: web) (step: rspec) /usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:61:in `query'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:749:in `column_definitions'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/abstract/schema_statements.rb:113:in `columns'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/schema_cache.rb:69:in `columns'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/connection_adapters/schema_cache.rb:75:in `columns_hash'
(service: web) (step: rspec) /usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/model_schema.rb:465:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/attributes.rb:234:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
(service: web) (step: rspec) /usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/model_schema.rb:458:in `block in load_schema'
(service: web) (step: rspec) /usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/model_schema.rb:455:in `load_schema'
(service: web) (step: rspec) /usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/model_schema.rb:346:in `attribute_types'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/attribute_methods.rb:219:in `has_attribute?'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/inheritance.rb:55:in `new'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/persistence.rb:35:in `create'
(service: web) (step: rspec) /usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/persistence.rb:33:in `block in create'
(service: web) (step: rspec) /usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/persistence.rb:33:in `collect'
/usr/local/bundle/gems/activerecord-5.2.0.rc1/lib/active_record/persistence.rb:33:in `create'
(service: web) (step: rspec) /app/db/seeds.rb:14:in `<main>'
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

1 participant