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

Fully separate schema: common vs tenant #117

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mjsteckel
Copy link

Consider this a proof of concept and not a formal pull request. I am sure that there are cleaner ways of accomplishing the functionality that I've implemented.

  1. maintain separation between "common" and tenant schemas (means that "common" tables are not also in the tenant schema!)
  2. tasks to process all tenants or a single tenant
  3. supports migrations for all tenants plus per tenant migrations (potentially scary)
  4. changed default so that db:migrate does NOT run apartment migrations.

There is work left to do to clean things up, for instance apartment:load is missing. Also, tests haven't been updated.

1) maintain separation between "common" and tenant schemas
   (means that "common" tables are not also in the tenant schema!)
2) taks to process all tenants or a single tenant
3) support for per tenant migrations (potentially scary)
4) changed default so that db:migrate does NOT run
   apartment migrations.
schema before executing any tenant migration.
end
end

def migration_paths(tenant)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure the previous impl, where one takes the AR migration_paths is so that engines that provide migrations could also be run. I didn't implement it, it was a PR, but I'm pretty sure this would revert that change. @linki can you comment?

@bradrobertson
Copy link
Contributor

I don't actually see any indication of splitting out the public schema from the tenanted schemas. It's definitely something I'd like to achieve, just haven't had the time to implement it.

Things to think about:

  1. schema.rb is generated from the default schema_search_path in Postgres, which by default is public. So, we'd need that schema to have all the tables we want in schema.rb. I've thought about possibly having an _apartment_excluded_models schema strictly for excluded models, then a separate schema (maybe _apartment_schema_rb?) that rails would use to generate the schema.rb file from.
  2. Having public in the schema_search_path (ie a persistent_schema) at all times will NOT work until we can properly separate the excluded models schema from the tenanted schema as you mentioned previously due to issues generating schema.rb. It's definitely a limitation at the moment.

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

Successfully merging this pull request may close these issues.

None yet

2 participants