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- 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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/railbow/status/section.rb', line 48 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.
38 39 40 |
# File 'lib/railbow/status/section.rb', line 38 def databases @databases end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
38 39 40 |
# File 'lib/railbow/status/section.rb', line 38 def entries @entries end |
#ghosts ⇒ Object (readonly)
Returns the value of attribute ghosts.
38 39 40 |
# File 'lib/railbow/status/section.rb', line 38 def ghosts @ghosts end |
#hidden_count ⇒ Object (readonly)
Returns the value of attribute hidden_count.
38 39 40 |
# File 'lib/railbow/status/section.rb', line 38 def hidden_count @hidden_count end |
#latest_applied_version ⇒ Object (readonly)
Returns the value of attribute latest_applied_version.
132 133 134 |
# File 'lib/railbow/status/section.rb', line 132 def latest_applied_version @latest_applied_version end |
#migrations_key ⇒ Object (readonly)
Returns the value of attribute migrations_key.
38 39 40 |
# File 'lib/railbow/status/section.rb', line 38 def migrations_key @migrations_key end |
#since_value ⇒ Object (readonly)
Returns the value of attribute since_value.
38 39 40 |
# File 'lib/railbow/status/section.rb', line 38 def since_value @since_value end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
38 39 40 |
# File 'lib/railbow/status/section.rb', line 38 def state @state end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
38 39 40 |
# File 'lib/railbow/status/section.rb', line 38 def total_count @total_count end |
Instance Method Details
#calendar ⇒ Object
163 164 165 166 |
# File 'lib/railbow/status/section.rb', line 163 def calendar build! unless @built @calendar end |
#columns ⇒ Object
138 139 140 141 |
# File 'lib/railbow/status/section.rb', line 138 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.
65 66 67 |
# File 'lib/railbow/status/section.rb', line 65 def database databases.first[:database] end |
#db_name ⇒ Object
69 70 71 |
# File 'lib/railbow/status/section.rb', line 69 def db_name databases.first[:name] end |
#db_names ⇒ Object
73 74 75 |
# File 'lib/railbow/status/section.rb', line 73 def db_names databases.map { |d| d[:name] } end |
#down_rows ⇒ Object
158 159 160 161 |
# File 'lib/railbow/status/section.rb', line 158 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.
44 45 46 |
# File 'lib/railbow/status/section.rb', line 44 def floor_applied? @floor_applied == true end |
#ghost_count ⇒ Object
128 129 130 |
# File 'lib/railbow/status/section.rb', line 128 def ghost_count @ghost_total ||= 0 end |
#ghost_rows ⇒ Object
153 154 155 156 |
# File 'lib/railbow/status/section.rb', line 153 def ghost_rows build! unless @built @ghost_rows end |
#highlight_rows ⇒ Object
148 149 150 151 |
# File 'lib/railbow/status/section.rb', line 148 def highlight_rows build! unless @built @highlight_rows end |
#latest_applied_date ⇒ Object
134 135 136 |
# File 'lib/railbow/status/section.rb', line 134 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.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/railbow/status/section.rb', line 84 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
124 125 126 |
# File 'lib/railbow/status/section.rb', line 124 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.
110 111 112 |
# File 'lib/railbow/status/section.rb', line 110 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.
120 121 122 |
# File 'lib/railbow/status/section.rb', line 120 def quiet? state != :ok end |
#rows ⇒ Object
143 144 145 146 |
# File 'lib/railbow/status/section.rb', line 143 def rows build! unless @built @rows end |
#same_migrations?(other) ⇒ Boolean
77 78 79 |
# File 'lib/railbow/status/section.rb', line 77 def same_migrations?(other) migrations_key == other.migrations_key end |
#sharded? ⇒ Boolean
102 103 104 |
# File 'lib/railbow/status/section.rb', line 102 def sharded? databases.size > 1 end |
#tick_col ⇒ Object
114 115 116 |
# File 'lib/railbow/status/section.rb', line 114 def tick_col TICK_COL end |