Class: Karafka::Web::Management::Migrations::Base
- Inherits:
-
Object
- Object
- Karafka::Web::Management::Migrations::Base
- Includes:
- Core::Helpers::Time
- Defined in:
- lib/karafka/web/management/migrations/0_base.rb
Overview
Base for all our migrations
Each migration MUST have a #migrate
method defined Migrations are expected to modify the provided state IN PLACE
Direct Known Subclasses
FillMissingReceivedAndSentBytesInConsumersMetrics, FillMissingReceivedAndSentBytesInConsumersState, IntroduceLagTotalInMetrics, IntroduceLagTotalInStates, IntroduceWaitingInConsumersMetrics, IntroduceWaitingInConsumersState, RemoveProcessingFromConsumersMetrics, RemoveProcessingFromConsumersState, RenameLagTotalToLagHybridInMetrics, RenameLagTotalToLagHybridInStates, SetInitialConsumersMetrics, SetInitialConsumersState, SplitListenersIntoActiveAndPausedInMetrics, SplitListenersIntoActiveAndPausedInStates
Class Attribute Summary collapse
-
.type ⇒ Object
What resource does it relate it One migration should modify only one resource type.
-
.versions_until ⇒ Object
First version that should NOT be affected by this migration.
Class Method Summary collapse
-
.applicable?(version) ⇒ Boolean
Is the given migration applicable.
-
.index ⇒ Integer
Index for sorting.
- .migrate(state) ⇒ Object
-
.sorted_descendants ⇒ Array<Class>
Array with migrations sorted from oldest to latest.
Class Attribute Details
.type ⇒ Object
What resource does it relate it One migration should modify only one resource type
20 21 22 |
# File 'lib/karafka/web/management/migrations/0_base.rb', line 20 def type @type end |
.versions_until ⇒ Object
First version that should NOT be affected by this migration
17 18 19 |
# File 'lib/karafka/web/management/migrations/0_base.rb', line 17 def versions_until @versions_until end |
Class Method Details
.applicable?(version) ⇒ Boolean
Returns is the given migration applicable.
24 25 26 |
# File 'lib/karafka/web/management/migrations/0_base.rb', line 24 def applicable?(version) version < versions_until end |
.index ⇒ Integer
Returns index for sorting. Older migrations are always applied first.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/karafka/web/management/migrations/0_base.rb', line 34 def index instance_method(:migrate) .source_location .first .split('/') .last .split('_') .first .to_i end |
.migrate(state) ⇒ Object
29 30 31 |
# File 'lib/karafka/web/management/migrations/0_base.rb', line 29 def migrate(state) raise NotImplementedError, 'Implement in a subclass' end |
.sorted_descendants ⇒ Array<Class>
Returns array with migrations sorted from oldest to latest. This is the order in which they need to be applied.
47 48 49 50 51 52 |
# File 'lib/karafka/web/management/migrations/0_base.rb', line 47 def sorted_descendants ObjectSpace .each_object(Class) .select { |klass| klass < self } .sort_by(&:index) end |