Class: Railbow::Status::Section
- Inherits:
-
Object
- Object
- Railbow::Status::Section
- Defined in:
- lib/railbow/status/section.rb
Overview
One migrations directory's worth of db:migrate:status.
Usually that is one database. Databases sharing a migrations_paths (the shape horizontal sharding takes) see the same files and differ only in what they have applied, so they merge into a single section carrying a status per database.
Rows are built lazily, on first read, because merging has to finish before the status cells can be built. A section never prints: Printer owns output, which is what lets sections share column widths.
Constant Summary collapse
- TICK_COL =
Index of the Date column, where calendar week ticks are drawn.
2- NAME_COL_WIDTH =
Width the Migration Name column is capped at once anything competes with it for horizontal space (tags, authors, table names).
60- NAME_COL_MIN_WIDTH =
Floor the width budget may shrink the name column down to on a narrow terminal, before it starts dropping columns instead.
24- NO_FILE =
"NO FILE"- ABSENT =
A version one database in a shard group has and another does not.
"ยท"
Instance Attribute Summary collapse
-
#databases ⇒ Object
readonly
Returns the value of attribute databases.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#ghosts ⇒ Object
readonly
Returns the value of attribute ghosts.
-
#hidden_count ⇒ Object
readonly
Returns the value of attribute hidden_count.
-
#latest_applied_version ⇒ Object
readonly
Returns the value of attribute latest_applied_version.
-
#migrations_key ⇒ Object
readonly
Returns the value of attribute migrations_key.
-
#since_value ⇒ Object
readonly
Returns the value of attribute since_value.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
- #calendar ⇒ Object
- #columns ⇒ Object
-
#database ⇒ Object
The database this section is named after.
- #db_name ⇒ Object
- #db_names ⇒ Object
- #down_rows ⇒ Object
-
#floor_applied? ⇒ Boolean
True when the time window left too few rows and the floor topped the section back up, which is worth saying out loud: the table then shows migrations from outside the window it advertises.
- #ghost_count ⇒ Object
- #ghost_rows ⇒ Object
- #highlight_rows ⇒ Object
-
#initialize(pool) ⇒ Section
constructor
A new instance of Section.
- #latest_applied_date ⇒ Object
-
#merge!(other) ⇒ Object
Folds another database that runs the same migration files into this section: its statuses join the existing rows, its identity joins the header, and anything already built is discarded.
- #pending_count ⇒ Object
-
#pending_in_view? ⇒ Boolean
Whether any row this section would render is still pending.
-
#quiet? ⇒ Boolean
Nothing in the window and nothing pending: the section has no table worth drawing, only a line saying so.
- #rows ⇒ Object
- #same_migrations?(other) ⇒ Boolean
- #sharded? ⇒ Boolean
- #tick_col ⇒ Object
Constructor Details
#initialize(pool) ⇒ Section
Returns a new instance of Section.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/railbow/status/section.rb', line 52 def initialize(pool) @formatter = Formatters::Base.new @databases = [{name: pool.db_config.name, database: pool.db_config.database}] @migrations_key = migrations_key_for(pool) @entries = {} @ghosts = {} @hidden_count = 0 @total_count = 0 @window_count = 0 @floor_applied = false @since_value = Railbow::Params.since collect(pool) end |
Instance Attribute Details
#databases ⇒ Object (readonly)
Returns the value of attribute databases.
42 43 44 |
# File 'lib/railbow/status/section.rb', line 42 def databases @databases end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
42 43 44 |
# File 'lib/railbow/status/section.rb', line 42 def entries @entries end |
#ghosts ⇒ Object (readonly)
Returns the value of attribute ghosts.
42 43 44 |
# File 'lib/railbow/status/section.rb', line 42 def ghosts @ghosts end |
#hidden_count ⇒ Object (readonly)
Returns the value of attribute hidden_count.
42 43 44 |
# File 'lib/railbow/status/section.rb', line 42 def hidden_count @hidden_count end |
#latest_applied_version ⇒ Object (readonly)
Returns the value of attribute latest_applied_version.
136 137 138 |
# File 'lib/railbow/status/section.rb', line 136 def latest_applied_version @latest_applied_version end |
#migrations_key ⇒ Object (readonly)
Returns the value of attribute migrations_key.
42 43 44 |
# File 'lib/railbow/status/section.rb', line 42 def migrations_key @migrations_key end |
#since_value ⇒ Object (readonly)
Returns the value of attribute since_value.
42 43 44 |
# File 'lib/railbow/status/section.rb', line 42 def since_value @since_value end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
42 43 44 |
# File 'lib/railbow/status/section.rb', line 42 def state @state end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
42 43 44 |
# File 'lib/railbow/status/section.rb', line 42 def total_count @total_count end |
Instance Method Details
#calendar ⇒ Object
167 168 169 170 |
# File 'lib/railbow/status/section.rb', line 167 def calendar build! unless @built @calendar end |
#columns ⇒ Object
142 143 144 145 |
# File 'lib/railbow/status/section.rb', line 142 def columns build! unless @built @columns end |
#database ⇒ Object
The database this section is named after. Multi-database sections use #databases; this is the single-database convenience.
69 70 71 |
# File 'lib/railbow/status/section.rb', line 69 def database databases.first[:database] end |
#db_name ⇒ Object
73 74 75 |
# File 'lib/railbow/status/section.rb', line 73 def db_name databases.first[:name] end |
#db_names ⇒ Object
77 78 79 |
# File 'lib/railbow/status/section.rb', line 77 def db_names databases.map { |d| d[:name] } end |
#down_rows ⇒ Object
162 163 164 165 |
# File 'lib/railbow/status/section.rb', line 162 def down_rows build! unless @built @down_rows end |
#floor_applied? ⇒ Boolean
True when the time window left too few rows and the floor topped the section back up, which is worth saying out loud: the table then shows migrations from outside the window it advertises.
48 49 50 |
# File 'lib/railbow/status/section.rb', line 48 def floor_applied? @floor_applied == true end |
#ghost_count ⇒ Object
132 133 134 |
# File 'lib/railbow/status/section.rb', line 132 def ghost_count @ghost_total ||= 0 end |
#ghost_rows ⇒ Object
157 158 159 160 |
# File 'lib/railbow/status/section.rb', line 157 def ghost_rows build! unless @built @ghost_rows end |
#highlight_rows ⇒ Object
152 153 154 155 |
# File 'lib/railbow/status/section.rb', line 152 def highlight_rows build! unless @built @highlight_rows end |
#latest_applied_date ⇒ Object
138 139 140 |
# File 'lib/railbow/status/section.rb', line 138 def latest_applied_date version_date(latest_applied_version) if latest_applied_version end |
#merge!(other) ⇒ Object
Folds another database that runs the same migration files into this section: its statuses join the existing rows, its identity joins the header, and anything already built is discarded.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/railbow/status/section.rb', line 88 def merge!(other) other.entries.each do |version, entry| mine = (@entries[version] ||= {name: entry[:name], statuses: {}}) mine[:name] = entry[:name] if mine[:name].include?(NO_FILE) mine[:statuses].merge!(entry[:statuses]) end @databases.concat(other.databases) @ghosts = other.ghosts.merge(@ghosts) @total_count = [@total_count, other.total_count].max @hidden_count = [@hidden_count, other.hidden_count].max @pending_count = [pending_count, other.pending_count].max @ghost_total = [ghost_count, other.ghost_count].max @latest_applied_version = [latest_applied_version, other.latest_applied_version].compact.max @state = other.state if state_rank(other.state) > state_rank(@state) reset_built self end |
#pending_count ⇒ Object
128 129 130 |
# File 'lib/railbow/status/section.rb', line 128 def pending_count @pending_count ||= 0 end |
#pending_in_view? ⇒ Boolean
Whether any row this section would render is still pending. Answered from the collected entries, so asking costs no git work - which is the point, since it is asked in order to decide whether to build the rows at all.
114 115 116 |
# File 'lib/railbow/status/section.rb', line 114 def pending_in_view? entries.any? { |_, entry| entry[:statuses].value?("down") } end |
#quiet? ⇒ Boolean
Nothing in the window and nothing pending: the section has no table worth drawing, only a line saying so.
124 125 126 |
# File 'lib/railbow/status/section.rb', line 124 def quiet? state != :ok end |
#rows ⇒ Object
147 148 149 150 |
# File 'lib/railbow/status/section.rb', line 147 def rows build! unless @built @rows end |
#same_migrations?(other) ⇒ Boolean
81 82 83 |
# File 'lib/railbow/status/section.rb', line 81 def same_migrations?(other) migrations_key == other.migrations_key end |
#sharded? ⇒ Boolean
106 107 108 |
# File 'lib/railbow/status/section.rb', line 106 def sharded? databases.size > 1 end |
#tick_col ⇒ Object
118 119 120 |
# File 'lib/railbow/status/section.rb', line 118 def tick_col TICK_COL end |