culturecode_stagehand 0.7.12 → 0.7.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stagehand/database.rb +8 -7
- data/lib/stagehand/staging/model.rb +10 -2
- data/lib/stagehand/version.rb +1 -1
- data/lib/tasks/stagehand_tasks.rake +13 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a6d79d7749da33008302addc5f4ab7b6ef3f53a
|
4
|
+
data.tar.gz: b939f07f252406b5ce2c06eba0cbc968d79836d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bb90a7ba80ea273602a4d56e8d0d8b22495ed253e9c94444c14d8101c4e2dabbb65e144766decd57a5247ed53b0a7ba8f6b0e3a9c1b67706eed3b45cfce1f2f
|
7
|
+
data.tar.gz: 65a6462d3e10ff7ccbb18feb8d437cd409da00eba68901c3522c0149586b53da089e762c510cb712639e66265ad61ee2ca8317bf29653fdc9df21bf39c44fa88
|
data/lib/stagehand/database.rb
CHANGED
@@ -4,6 +4,11 @@ module Stagehand
|
|
4
4
|
|
5
5
|
@@connection_name_stack = [Rails.env.to_sym]
|
6
6
|
|
7
|
+
def each(&block)
|
8
|
+
with_connection(Configuration.staging_connection_name, &block)
|
9
|
+
with_connection(Configuration.production_connection_name, &block) unless Configuration.single_connection?
|
10
|
+
end
|
11
|
+
|
7
12
|
def connected_to_production?
|
8
13
|
current_connection_name == Configuration.production_connection_name
|
9
14
|
end
|
@@ -43,21 +48,17 @@ module Stagehand
|
|
43
48
|
Rails.logger.debug "Connecting to #{current_connection_name}"
|
44
49
|
connect_to(current_connection_name) if different
|
45
50
|
|
46
|
-
yield
|
51
|
+
yield connection_name
|
47
52
|
ensure
|
48
53
|
@@connection_name_stack.pop
|
49
54
|
Rails.logger.debug "Restoring connection to #{current_connection_name}"
|
50
55
|
connect_to(current_connection_name) if different
|
51
56
|
end
|
52
57
|
|
53
|
-
def set_connection_for_model(model, connection_name)
|
54
|
-
connect_to(connection_name, model) unless Configuration.ghost_mode?
|
55
|
-
end
|
56
|
-
|
57
58
|
private
|
58
59
|
|
59
|
-
def connect_to(connection_name
|
60
|
-
|
60
|
+
def connect_to(connection_name)
|
61
|
+
ActiveRecord::Base.establish_connection(connection_name)
|
61
62
|
end
|
62
63
|
|
63
64
|
def current_connection_name
|
@@ -3,8 +3,16 @@ module Stagehand
|
|
3
3
|
module Model
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
class_methods do
|
7
|
+
def connection
|
8
|
+
return super if Configuration.ghost_mode?
|
9
|
+
|
10
|
+
if Stagehand::Database.connected_to_production?
|
11
|
+
Stagehand::Database::StagingProbe.connection
|
12
|
+
else
|
13
|
+
ActiveRecord::Base.connection
|
14
|
+
end
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
10
18
|
end
|
data/lib/stagehand/version.rb
CHANGED
@@ -15,33 +15,21 @@ namespace :stagehand do
|
|
15
15
|
Stagehand::Staging::Synchronizer.sync_all
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
task
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
# Enhance the regular tasks to run on both staging and production databases
|
19
|
+
def rake_both_databases(task, stagehand_task = task.gsub(':','_'))
|
20
|
+
task(stagehand_task => :environment) do
|
21
|
+
Stagehand::Database.each do |connection_name|
|
22
|
+
puts "#{connection_name}"
|
23
|
+
Rake::Task[task].reenable
|
24
|
+
Rake::Task[task].invoke
|
25
|
+
end
|
26
|
+
Rake::Task[task].clear
|
23
27
|
end
|
24
|
-
Rake::Task['db:migrate'].clear
|
25
|
-
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
run_on_both_databases do
|
30
|
-
Rake::Task['db:rollback'].reenable
|
31
|
-
Rake::Task['db:rollback'].invoke
|
32
|
-
end
|
33
|
-
Rake::Task['db:rollback'].clear
|
29
|
+
# Enhance the original task to run the stagehand_task as a prerequisite
|
30
|
+
Rake::Task[task].enhance(["stagehand:#{stagehand_task}"])
|
34
31
|
end
|
35
|
-
end
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
connections.compact.uniq.each do |connection_name|
|
40
|
-
puts "#{connection_name}"
|
41
|
-
Stagehand::Database.with_connection(connection_name, &block)
|
42
|
-
end
|
33
|
+
rake_both_databases('db:migrate')
|
34
|
+
rake_both_databases('db:rollback')
|
43
35
|
end
|
44
|
-
|
45
|
-
# Enhance the regular db:migrate/db:rollback tasks to run the stagehand migration/rollback tasks so both stagehand databases are migrated
|
46
|
-
Rake::Task['db:migrate'].enhance(['stagehand:migrate'])
|
47
|
-
Rake::Task['db:rollback'].enhance(['stagehand:rollback'])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: culturecode_stagehand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Jakobsen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-07-
|
12
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|