File tree Expand file tree Collapse file tree 7 files changed +69
-13
lines changed Expand file tree Collapse file tree 7 files changed +69
-13
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ workflows:
70
70
matrix :
71
71
parameters :
72
72
ruby_version : ["ruby:2.6-buster", "ruby:2.7-buster"]
73
- gemfile : ["gemfiles/rails_5_2.gemfile", "gemfiles/rails_6_0.gemfile"]
73
+ gemfile : ["gemfiles/rails_5_2.gemfile", "gemfiles/rails_6_0.gemfile", "gemfiles/rails_6_1.gemfile" ]
74
74
75
75
rubocop :
76
76
jobs :
Original file line number Diff line number Diff line change @@ -45,14 +45,26 @@ appraise 'rails-6-0' do
45
45
end
46
46
end
47
47
48
+ appraise 'rails-6-1' do
49
+ gem 'rails' , '~> 6.1.0'
50
+ platforms :ruby do
51
+ gem 'sqlite3' , '~> 1.4'
52
+ end
53
+ platforms :jruby do
54
+ gem 'activerecord-jdbc-adapter' , '~> 61.0'
55
+ gem 'activerecord-jdbcpostgresql-adapter' , '~> 61.0'
56
+ gem 'activerecord-jdbcmysql-adapter' , '~> 61.0'
57
+ end
58
+ end
59
+
48
60
appraise 'rails-master' do
49
61
gem 'rails' , git : 'https://github.com/rails/rails.git'
50
62
platforms :ruby do
51
63
gem 'sqlite3' , '~> 1.4'
52
64
end
53
65
platforms :jruby do
54
- gem 'activerecord-jdbc-adapter' , '~> 52 .0'
55
- gem 'activerecord-jdbcpostgresql-adapter' , '~> 52 .0'
56
- gem 'activerecord-jdbcmysql-adapter' , '~> 52 .0'
66
+ gem 'activerecord-jdbc-adapter' , '~> 61 .0'
67
+ gem 'activerecord-jdbcpostgresql-adapter' , '~> 61 .0'
68
+ gem 'activerecord-jdbcmysql-adapter' , '~> 61 .0'
57
69
end
58
70
end
Original file line number Diff line number Diff line change
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+ gem "rubocop"
7
+
8
+ group :local do
9
+ gem "guard-rspec", "~> 4.2"
10
+ gem "pry"
11
+ end
12
+
13
+ platforms :ruby do
14
+ gem "sqlite3", "~> 1.4"
15
+ end
16
+
17
+ platforms :jruby do
18
+ gem "activerecord-jdbc-adapter", "~> 61.0"
19
+ gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
20
+ gem "activerecord-jdbcmysql-adapter", "~> 61.0"
21
+ end
22
+
23
+ gemspec path: "../"
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ class << self
27
27
28
28
WRITER_METHODS = %i[ tenant_names database_schema_file excluded_models
29
29
persistent_schemas connection_class
30
- db_migrate_tenants seed_data_file
30
+ db_migrate_tenants db_migrate_tenant_missing_strategy seed_data_file
31
31
parallel_migration_threads pg_excluded_names ] . freeze
32
32
33
33
attr_accessor ( *ACCESSOR_METHODS )
@@ -72,6 +72,21 @@ def db_migrate_tenants
72
72
@db_migrate_tenants = true
73
73
end
74
74
75
+ # How to handle tenant missing on db:migrate
76
+ # defaults to :rescue_exception
77
+ # available options: rescue_exception, raise_exception, create_tenant
78
+ def db_migrate_tenant_missing_strategy
79
+ valid = %i[ rescue_exception raise_exception create_tenant ]
80
+ value = @db_migrate_tenant_missing_strategy || :rescue_exception
81
+
82
+ return value if valid . include? ( value )
83
+
84
+ key_name = 'config.db_migrate_tenant_missing_strategy'
85
+ opt_names = valid . join ( ', ' )
86
+
87
+ raise ApartmentError , "Option #{ value } not valid for `#{ key_name } `. Use one of #{ opt_names } "
88
+ end
89
+
75
90
# Default to empty array
76
91
def excluded_models
77
92
@excluded_models || [ ]
Original file line number Diff line number Diff line change @@ -36,5 +36,17 @@ def self.create_tenant(tenant_name)
36
36
rescue Apartment ::TenantExists => e
37
37
puts "Tried to create already existing tenant: #{ e } "
38
38
end
39
+
40
+ def self . migrate_tenant ( tenant_name )
41
+ strategy = Apartment . db_migrate_tenant_missing_strategy
42
+ create_tenant ( tenant_name ) if strategy == :create_tenant
43
+
44
+ puts ( "Migrating #{ tenant_name } tenant" )
45
+ Apartment ::Migrator . migrate tenant_name
46
+ rescue Apartment ::TenantNotFound => e
47
+ raise e if strategy == :raise_exception
48
+
49
+ puts e . message
50
+ end
39
51
end
40
52
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module Apartment
4
- VERSION = '2.8.1 '
4
+ VERSION = '2.9.0 '
5
5
end
Original file line number Diff line number Diff line change @@ -30,13 +30,7 @@ apartment_namespace = namespace :apartment do
30
30
task :migrate do
31
31
Apartment ::TaskHelper . warn_if_tenants_empty
32
32
Apartment ::TaskHelper . each_tenant do |tenant |
33
- begin
34
- Apartment ::TaskHelper . create_tenant ( tenant )
35
- puts ( "Migrating #{ tenant } tenant" )
36
- Apartment ::Migrator . migrate tenant
37
- rescue Apartment ::TenantNotFound => e
38
- puts e . message
39
- end
33
+ Apartment ::TaskHelper . migrate_tenant ( tenant )
40
34
end
41
35
end
42
36
You can’t perform that action at this time.
0 commit comments