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

excluded_models from migrations in engines are run for each tenant #634

Open
bjensen opened this issue Jan 31, 2020 · 0 comments
Open

excluded_models from migrations in engines are run for each tenant #634

bjensen opened this issue Jan 31, 2020 · 0 comments

Comments

@bjensen
Copy link

bjensen commented Jan 31, 2020

Steps to reproduce

Make a engine and add the following lets call it Project

Add the following to its lib/project/engine.rb:

  class Engine < ::Rails::Engine
    isolate_namespace Project

    initializer :append_migrations do |app|
      unless app.root.to_s.match root.to_s
        config.paths["db/migrate"].expanded.each do |expanded_path|
          app.config.paths["db/migrate"] << expanded_path
        end
      end
    end
  end
end

Add some models in the rails engine e.g. User

now put the rails engine in your Gemfile and do a bundle install

and Add the following to your appartment.rb initializer:

project_models = Project.constants.map{|c| Project.const_get(c) }.select do |const|
  const.class == Class && const < ActiveRecord::Base
end

config.excluded_models = project_models

Expected behavior

The migration for Project::User is run once and located in the public search path

Actual behavior

The migration for Project::User located in the public search path but run for every tenant, so you get this error: PG::DuplicateTable: ERROR: relation "project_users" already exists

System configuration

  • Database: Postgres 11.2

  • Apartment version: Newest from development branch

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

    • use_schemas: (true or false): true
  • Rails (or ActiveRecord) version: 6.0.2.1

  • Ruby version: 2.3

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