Module: Railbow::MultiDb
- Defined in:
- lib/railbow/multi_db.rb
Overview
Rails runs db:migrate:status once per database, inside with_temporary_pool_for_each. Each call on its own cannot know whether more databases are coming, so railbow wraps that loop: sections collect into the open batch and the batch renders them together when the loop ends.
A batch is inert unless something adds to it, so wrapping the other tasks that share the same Rails helper (db:migrate, db:prepare) costs one object.
Defined Under Namespace
Classes: Batch
Constant Summary collapse
- KEY =
:railbow_multi_db_batch
Class Method Summary collapse
-
.batch ⇒ Object
Opens a batch for the duration of the block.
-
.claim_help ⇒ Object
True the first time it is asked within a run.
- .current ⇒ Object
Class Method Details
.batch ⇒ Object
Opens a batch for the duration of the block. The flush is in an ensure so that a database aborting mid-run (a missing schema_migrations table, say) still prints the sections collected before it.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/railbow/multi_db.rb', line 65 def batch previous = Thread.current[KEY] batch = Batch.new Thread.current[KEY] = batch begin yield ensure Thread.current[KEY] = previous batch.flush end end |
.claim_help ⇒ Object
True the first time it is asked within a run. Without a batch every call is its own run, so the answer is always true.
83 84 85 |
# File 'lib/railbow/multi_db.rb', line 83 def claim_help current ? current.claim_help : true end |
.current ⇒ Object
77 78 79 |
# File 'lib/railbow/multi_db.rb', line 77 def current Thread.current[KEY] end |