penthouse 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/penthouse/migrator.rb +103 -39
- data/lib/penthouse/tenants/schema_tenant.rb +1 -0
- data/lib/penthouse/version.rb +1 -1
- data/lib/penthouse.rb +4 -3
- metadata +1 -3
- data/lib/penthouse/railtie.rb +0 -11
- data/lib/tasks/penthouse.rake +0 -96
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c2f7032744a162f8d7841fb997536f71ed30c74
|
4
|
+
data.tar.gz: 74dc6c8881eaa3b869f0ad078217632a8037bed6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 776a192ee3c89480cd2fe9124aa65bba125d3d97c716dffcd0300b462d42cf400cc5f014836007608f8fa8ec0f7b32daf2aabba84d67ffb1e2250ce705f83bfd
|
7
|
+
data.tar.gz: 8e2ce6d50bdb1cac77fdec1bd97a9135344fd98d3a83acedc5148a0bd9f8ce8f8dae19f8a2784bb77420849f39914781cc8863fcc91b9624edf178c80e9eae26
|
data/lib/penthouse/migrator.rb
CHANGED
@@ -1,56 +1,120 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'active_record'
|
2
|
+
require 'set'
|
3
|
+
require 'active_support/core_ext/module/aliasing'
|
4
|
+
require 'active_support/core_ext/array/wrap'
|
5
5
|
|
6
6
|
module Penthouse
|
7
|
-
module
|
7
|
+
module Migration
|
8
|
+
def self.included(base)
|
9
|
+
base.alias_method_chain :announce, :penthouse
|
10
|
+
end
|
11
|
+
|
12
|
+
def announce_with_penthouse(message)
|
13
|
+
announce_without_penthouse("#{message} - #{current_tenant}")
|
14
|
+
end
|
8
15
|
|
9
|
-
|
16
|
+
def current_tenant
|
17
|
+
"Tenant: #{Penthouse.tenant || '*** global ***'}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
10
21
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
module Penthouse
|
23
|
+
module Migrator
|
24
|
+
def self.included(base)
|
25
|
+
base.extend(ClassMethods)
|
26
|
+
|
27
|
+
base.class_eval do
|
28
|
+
class << self
|
29
|
+
alias_method_chain :migrate, :penthouse
|
30
|
+
alias_method_chain :up, :penthouse
|
31
|
+
alias_method_chain :down, :penthouse
|
32
|
+
alias_method_chain :run, :penthouse
|
20
33
|
end
|
21
34
|
end
|
22
35
|
end
|
23
36
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
module ClassMethods
|
38
|
+
def migrate_with_penthouse(migrations_paths, target_version = nil, &block)
|
39
|
+
unless Penthouse.configuration.migrate_tenants?
|
40
|
+
if defined?(:migrate_without_octopus)
|
41
|
+
return migrate_without_octopus(migrations_paths, target_version, &block)
|
42
|
+
else
|
43
|
+
return migrate_without_penthouse(migrations_paths, target_version, &block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Penthouse.each_tenant(tenant_identifiers: tenants_to_migrate) do
|
48
|
+
if defined?(:migrate_without_octopus)
|
49
|
+
migrate_without_octopus(migrations_paths, target_version, &block)
|
50
|
+
else
|
51
|
+
migrate_without_penthouse(migrations_paths, target_version, &block)
|
52
|
+
end
|
34
53
|
end
|
35
54
|
end
|
36
|
-
end
|
37
55
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
56
|
+
def up_with_penthouse(migrations_paths, target_version = nil, &block)
|
57
|
+
unless Penthouse.configuration.migrate_tenants?
|
58
|
+
if defined?(:up_without_octopus)
|
59
|
+
return up_without_octopus(migrations_paths, target_version, &block)
|
60
|
+
else
|
61
|
+
return up_without_penthouse(migrations_paths, target_version, &block)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
Penthouse.each_tenant(tenant_identifiers: tenants_to_migrate) do
|
66
|
+
if defined?(:up_without_octopus)
|
67
|
+
up_without_octopus(migrations_paths, target_version, &block)
|
68
|
+
else
|
69
|
+
up_without_penthouse(migrations_paths, target_version, &block)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def down_with_penthouse(migrations_paths, target_version = nil, &block)
|
75
|
+
unless Penthouse.configuration.migrate_tenants?
|
76
|
+
if defined?(:down_without_octopus)
|
77
|
+
return down_without_octopus(migrations_paths, target_version, &block)
|
78
|
+
else
|
79
|
+
return down_without_penthouse(migrations_paths, target_version, &block)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
Penthouse.each_tenant(tenant_identifiers: tenants_to_migrate) do
|
84
|
+
if defined?(:down_without_octopus)
|
85
|
+
down_without_octopus(migrations_paths, target_version, &block)
|
86
|
+
else
|
87
|
+
down_without_penthouse(migrations_paths, target_version, &block)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def run_with_penthouse(direction, migrations_paths, target_version)
|
93
|
+
unless Penthouse.configuration.migrate_tenants?
|
94
|
+
if defined?(:run_without_octopus)
|
95
|
+
return run_without_octopus(direction, migrations_paths, target_version)
|
96
|
+
else
|
97
|
+
return run_without_penthouse(direction, migrations_paths, target_version)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
Penthouse.each_tenant(tenant_identifiers: tenants_to_migrate) do
|
102
|
+
if defined?(:run_without_octopus)
|
103
|
+
run_without_octopus(direction, migrations_paths, target_version)
|
104
|
+
else
|
105
|
+
run_without_penthouse(direction, migrations_paths, target_version)
|
106
|
+
end
|
48
107
|
end
|
49
108
|
end
|
50
|
-
end
|
51
109
|
|
52
|
-
|
53
|
-
|
110
|
+
def tenants_to_migrate
|
111
|
+
if (t = ENV["tenant"] || ENV["tenants"])
|
112
|
+
t.split(",").map(&:strip)
|
113
|
+
end
|
114
|
+
end
|
54
115
|
end
|
55
116
|
end
|
56
117
|
end
|
118
|
+
|
119
|
+
ActiveRecord::Migration.send(:include, Penthouse::Migration)
|
120
|
+
ActiveRecord::Migrator.send(:include, Penthouse::Migrator)
|
data/lib/penthouse/version.rb
CHANGED
data/lib/penthouse.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "penthouse/
|
1
|
+
require "penthouse/migrator"
|
2
2
|
require "penthouse/version"
|
3
3
|
require "penthouse/configuration"
|
4
4
|
require "penthouse/routers/base_router"
|
@@ -37,12 +37,13 @@ module Penthouse
|
|
37
37
|
|
38
38
|
# Wraps Penthouse.switch and simply executes the block of code for each
|
39
39
|
# tenant within Penthouse.tenant_identifiers
|
40
|
+
# @param tenant_identifiers [Array<String, Symbol>, nil] the array of tenants to loop through
|
40
41
|
# @param default_tenant [String, Symbol] the identifier for the tenant to return to
|
41
42
|
# @param block [Block] the code to execute
|
42
43
|
# @yield [String, Symbol] the identifier for the tenant
|
43
44
|
# @return [void]
|
44
|
-
def each_tenant(default_tenant: tenant, runner: configuration.runner, &block)
|
45
|
-
tenant_identifiers.each do |tenant_identifier|
|
45
|
+
def each_tenant(tenant_identifiers: nil, default_tenant: tenant, runner: configuration.runner, &block)
|
46
|
+
(tenant_identifiers || self.tenant_identifiers).each do |tenant_identifier|
|
46
47
|
switch(tenant_identifier, runner: runner, &block)
|
47
48
|
end
|
48
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: penthouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Townsend
|
@@ -170,7 +170,6 @@ files:
|
|
170
170
|
- lib/penthouse/app.rb
|
171
171
|
- lib/penthouse/configuration.rb
|
172
172
|
- lib/penthouse/migrator.rb
|
173
|
-
- lib/penthouse/railtie.rb
|
174
173
|
- lib/penthouse/routers/base_router.rb
|
175
174
|
- lib/penthouse/routers/subdomain_router.rb
|
176
175
|
- lib/penthouse/runners/base_runner.rb
|
@@ -186,7 +185,6 @@ files:
|
|
186
185
|
- lib/penthouse/tenants/octopus_shard_tenant.rb
|
187
186
|
- lib/penthouse/tenants/schema_tenant.rb
|
188
187
|
- lib/penthouse/version.rb
|
189
|
-
- lib/tasks/penthouse.rake
|
190
188
|
- penthouse.gemspec
|
191
189
|
homepage: https://github.com/ryantownsend/penthouse
|
192
190
|
licenses: []
|
data/lib/penthouse/railtie.rb
DELETED
data/lib/tasks/penthouse.rake
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'penthouse/migrator'
|
2
|
-
|
3
|
-
penthouse_namespace = namespace :penthouse do
|
4
|
-
|
5
|
-
desc "Migrate all tenants to latest version"
|
6
|
-
task :migrate do
|
7
|
-
warn_if_tenants_empty
|
8
|
-
|
9
|
-
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
10
|
-
|
11
|
-
tenant_identifiers.each do |tenant_identifier|
|
12
|
-
begin
|
13
|
-
puts("Migrating #{tenant_identifier || '***global***'} tenant")
|
14
|
-
Penthouse::Migrator.migrate(tenant_identifier, version)
|
15
|
-
rescue Penthouse::TenantNotFound => e
|
16
|
-
puts e.message
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
desc "Rolls the migration back to the previous version (specify steps w/ STEP=n) across all tenants."
|
22
|
-
task :rollback do
|
23
|
-
warn_if_tenants_empty
|
24
|
-
|
25
|
-
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
26
|
-
|
27
|
-
tenant_identifiers.each do |tenant_identifier|
|
28
|
-
begin
|
29
|
-
puts("Rolling back #{tenant_identifier || '***global***'} tenant")
|
30
|
-
Penthouse::Migrator.rollback(tenant_identifier, step)
|
31
|
-
rescue Penthouse::TenantNotFound => e
|
32
|
-
puts e.message
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
namespace :migrate do
|
38
|
-
desc 'Runs the "up" for a given migration VERSION across all tenants.'
|
39
|
-
task :up do
|
40
|
-
warn_if_tenants_empty
|
41
|
-
|
42
|
-
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
43
|
-
raise 'VERSION is required' unless version
|
44
|
-
|
45
|
-
tenant_identifiers.each do |tenant_identifier|
|
46
|
-
begin
|
47
|
-
puts("Migrating #{tenant_identifier || '***global***'} tenant up")
|
48
|
-
Penthouse::Migrator.run(:up, tenant_identifier, version)
|
49
|
-
rescue Penthouse::TenantNotFound => e
|
50
|
-
puts e.message
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
desc 'Runs the "down" for a given migration VERSION across all tenants.'
|
56
|
-
task :down do
|
57
|
-
warn_if_tenants_empty
|
58
|
-
|
59
|
-
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
60
|
-
raise 'VERSION is required' unless version
|
61
|
-
|
62
|
-
tenant_identifiers.each do |tenant_identifier|
|
63
|
-
begin
|
64
|
-
puts("Migrating #{tenant_identifier || '***global***'} tenant down")
|
65
|
-
Penthouse::Migrator.run(:down, tenant_identifier, version)
|
66
|
-
rescue Penthouse::TenantNotFound => e
|
67
|
-
puts e.message
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
desc 'Rolls back the tenant one migration and re-migrate up (options: STEP=x, VERSION=x).'
|
73
|
-
task :redo do
|
74
|
-
if ENV['VERSION']
|
75
|
-
penthouse_namespace['migrate:down'].invoke
|
76
|
-
penthouse_namespace['migrate:up'].invoke
|
77
|
-
else
|
78
|
-
penthouse_namespace['rollback'].invoke
|
79
|
-
penthouse_namespace['migrate'].invoke
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def tenant_identifiers
|
85
|
-
Penthouse.tenant_identifiers
|
86
|
-
end
|
87
|
-
|
88
|
-
def warn_if_tenants_empty
|
89
|
-
if tenant_identifiers.empty?
|
90
|
-
puts <<-WARNING
|
91
|
-
[WARNING] - The list of tenants to migrate appears to be empty. This could mean you've not created any.
|
92
|
-
Note that your tenants currently haven't been migrated. You'll need to run `db:migrate` to rectify this.
|
93
|
-
WARNING
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|