Module: Stagehand::Database
Defined Under Namespace
Modules: ConnectionStack Classes: Probe, ProductionProbe, StagingProbe
Instance Method Summary collapse
- #connected_to_production? ⇒ Boolean
- #connected_to_staging? ⇒ Boolean
- #each(&block) ⇒ Object
- #production_connection ⇒ Object
- #production_database_name ⇒ Object
- #production_database_versions ⇒ Object
- #staging_connection ⇒ Object
- #staging_database_name ⇒ Object
- #staging_database_versions ⇒ Object
- #transaction ⇒ Object
- #with_connection(connection_name, &block) ⇒ Object
- #with_production_connection(&block) ⇒ Object
- #with_staging_connection(&block) ⇒ Object
Instance Method Details
#connected_to_production? ⇒ Boolean
13 14 15 |
# File 'lib/stagehand/database.rb', line 13 def connected_to_production? current_connection_name == Configuration.production_connection_name end |
#connected_to_staging? ⇒ Boolean
17 18 19 |
# File 'lib/stagehand/database.rb', line 17 def connected_to_staging? current_connection_name == Configuration.staging_connection_name end |
#each(&block) ⇒ Object
8 9 10 11 |
# File 'lib/stagehand/database.rb', line 8 def each(&block) with_production_connection(&block) unless Configuration.single_connection? with_staging_connection(&block) end |
#production_connection ⇒ Object
21 22 23 |
# File 'lib/stagehand/database.rb', line 21 def production_connection ProductionProbe.connection end |
#production_database_name ⇒ Object
29 30 31 |
# File 'lib/stagehand/database.rb', line 29 def production_database_name database_name(Configuration.production_connection_name) end |
#production_database_versions ⇒ Object
41 42 43 |
# File 'lib/stagehand/database.rb', line 41 def production_database_versions Stagehand::Database.production_connection.select_values(versions_scope) end |
#staging_connection ⇒ Object
25 26 27 |
# File 'lib/stagehand/database.rb', line 25 def staging_connection StagingProbe.connection end |
#staging_database_name ⇒ Object
33 34 35 |
# File 'lib/stagehand/database.rb', line 33 def staging_database_name database_name(Configuration.staging_connection_name) end |
#staging_database_versions ⇒ Object
37 38 39 |
# File 'lib/stagehand/database.rb', line 37 def staging_database_versions Stagehand::Database.staging_connection.select_values(versions_scope) end |
#transaction ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/stagehand/database.rb', line 65 def transaction success = false output = nil ActiveRecord::Base.transaction do Production::Record.transaction do output = yield success = true end raise ActiveRecord::Rollback unless success end return output end |
#with_connection(connection_name, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/stagehand/database.rb', line 53 def with_connection(connection_name, &block) if current_connection_name != connection_name.to_sym Rails.logger.debug "Connecting to #{connection_name}" output = swap_connection(connection_name, &block) Rails.logger.debug "Restoring connection to #{current_connection_name}" else Rails.logger.debug "Already connected to #{connection_name}" output = yield connection_name end return output end |
#with_production_connection(&block) ⇒ Object
49 50 51 |
# File 'lib/stagehand/database.rb', line 49 def with_production_connection(&block) with_connection(Configuration.production_connection_name, &block) end |
#with_staging_connection(&block) ⇒ Object
45 46 47 |
# File 'lib/stagehand/database.rb', line 45 def with_staging_connection(&block) with_connection(Configuration.staging_connection_name, &block) end |