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/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
ConsumersMetrics::FillMissingReceivedAndSentBytes, ConsumersMetrics::IntroduceLagTotal, ConsumersMetrics::IntroduceWaiting, ConsumersMetrics::PopulateJobsMetrics, ConsumersMetrics::RemoveProcessing, ConsumersMetrics::RenameLagTotalToLagHybrid, ConsumersMetrics::SetInitial, ConsumersMetrics::SplitListenersIntoActiveAndPaused, ConsumersReports::AddGroupInstanceIdToSubscriptionGroups, ConsumersReports::AddPollIntervalToSubscriptionGroups, ConsumersReports::RenameProcessNameToId, ConsumersStates::AddJobsCounter, ConsumersStates::FillMissingReceivedAndSentBytes, ConsumersStates::IntroduceLagTotal, ConsumersStates::IntroduceWaiting, ConsumersStates::RemoveProcessing, ConsumersStates::RenameLagTotalToLagHybrid, ConsumersStates::SetInitial, ConsumersStates::SplitListenersIntoActiveAndPaused
Class Attribute Summary collapse
-
.type ⇒ Object
What resource does it relate it.
-
.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
19 20 21 |
# File 'lib/karafka/web/management/migrations/base.rb', line 19 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/base.rb', line 17 def versions_until @versions_until end |
Class Method Details
.applicable?(version) ⇒ Boolean
Returns is the given migration applicable.
23 24 25 |
# File 'lib/karafka/web/management/migrations/base.rb', line 23 def applicable?(version) version < versions_until end |
.index ⇒ Integer
Returns index for sorting. Older migrations are always applied first.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/karafka/web/management/migrations/base.rb', line 33 def index instance_method(:migrate) .source_location .first .split("/") .last .split("_") .first .to_i end |
.migrate(state) ⇒ Object
28 29 30 |
# File 'lib/karafka/web/management/migrations/base.rb', line 28 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.
46 47 48 49 50 51 |
# File 'lib/karafka/web/management/migrations/base.rb', line 46 def sorted_descendants ObjectSpace .each_object(Class) .select { |klass| klass != self && klass.ancestors.include?(self) } .sort_by(&:index) end |