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

[WIP] Add config for handling tenant creation on db:migrate #140

Merged
merged 2 commits into from
Jan 21, 2021
Merged

[WIP] Add config for handling tenant creation on db:migrate #140

merged 2 commits into from
Jan 21, 2021

Conversation

jonian
Copy link
Contributor

@jonian jonian commented Dec 18, 2020

This is a proposal to resolve issue #136 by making the create_tenant on db:migrate behavior configurable. Added config key db_migrate_tenant_missing_strategy defaulting to rescue_exception with available options:

  • rescue_exception
  • raise_exception
  • create_tenant

The default option has the same behavior as it was before version 2.8.0. If this is ok, I can procceed to add specs for the new config option.

@Aesthetikx
Copy link

Thanks for working on this, I ran into (with 2.8.1) a bunch of tried to create tenant errors (although they were handled and did not crash) when otherwise I would have had no output other than 'migrating xyz tenant'. To be clear, to get the old behavior, would that be the 'rescue exception' option?

@jonian
Copy link
Contributor Author

jonian commented Dec 19, 2020

Yes rescue_exception is the old behavior, you get a tenant not found message and the task continues to the next tenant.

There is no check for rescue_exception in this PR and it can be replaced by nil or do_nothing or whatever sounds better.

Code before 2.8.0

def self.migrate_tenant(tenant_name)
  puts("Migrating #{tenant_name} tenant")
  Apartment::Migrator.migrate tenant_name
rescue Apartment::TenantNotFound => e
  puts e.message
end

Code after 2.8.0

def self.migrate_tenant(tenant_name)
  create_tenant(tenant_name) # create tenant was added

  puts("Migrating #{tenant_name} tenant")
  Apartment::Migrator.migrate tenant_name
rescue Apartment::TenantNotFound => e
  puts e.message
end

Code in this PR

def self.migrate_tenant(tenant_name)
  strategy = Apartment.db_migrate_tenant_missing_strategy
  create_tenant(tenant_name) if strategy == :create_tenant # enables behavior like in 2.8.0

  puts("Migrating #{tenant_name} tenant")
  Apartment::Migrator.migrate tenant_name
rescue Apartment::TenantNotFound => e
  raise e if strategy == :raise_exception # new behavior if you want to stop the migration

  puts e.message
end

@rpbaltazar
Copy link
Contributor

Thank you for working on this. looks great! 👍

@rpbaltazar rpbaltazar merged commit 8ab8bbd into rails-on-services:development Jan 21, 2021
rpbaltazar added a commit that referenced this pull request Jan 21, 2021
Prepare Release - 2.9.0

**Implemented enhancements:**

- Add config for handling tenant creation on db:migrate - #140

**Fixed bugs:**

**Closed issues:**

- Tenant exists errors on migrate task on 2.8.0 [#136](#136)
- Add Rails 6.1 to build matrix #144
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.

3 participants