Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api] allow multiple parallel updateinfo counters per incident
They depend on the scheme to support different code streams from one incident. Furthermore only the counter of the default scheme was used before
- Loading branch information
1 parent
31d059f
commit 474a24f
Showing
6 changed files
with
118 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class IncidentUpdateinfoCounterValue < ActiveRecord::Base | ||
|
||
belongs_to :updateinfo_counter | ||
belongs_to :project | ||
|
||
def self.find_or_create(time, updateinfo_counter, project) | ||
|
||
icv = IncidentUpdateinfoCounterValue.where(updateinfo_counter:updateinfo_counter, project: project).first | ||
return icv if icv | ||
|
||
# not yet released, get an uniq counter value for this incident and scheme | ||
IncidentUpdateinfoCounterValue.create(released_at: time, | ||
updateinfo_counter:updateinfo_counter, | ||
project: project, | ||
value: updateinfo_counter.increase) | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class UpdateinfoCounter < ActiveRecord::Base | ||
|
||
def self.find_or_create(time, maintenance_project, template) | ||
year = month = day = nil | ||
|
||
year = time.year if template =~ /%Y/ | ||
month = time.month if template =~ /%M/ | ||
day = time.day if template =~ /%D/ | ||
|
||
r = UpdateinfoCounter.where(year: year, month: month, day: day).first | ||
r = UpdateinfoCounter.create(year: year, month: month, day: day) unless r | ||
|
||
r | ||
end | ||
|
||
def increase | ||
# do an atomic increase of counter | ||
counter = nil | ||
self.transaction do | ||
self.lock! | ||
self.increment!(:counter) | ||
counter = self.counter | ||
self.save! | ||
end | ||
return counter | ||
end | ||
|
||
end | ||
|
41 changes: 41 additions & 0 deletions
41
src/api/db/migrate/20150625105426_multiple_incident_counters.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
class TempMI < ActiveRecord::Base | ||
self.table_name = 'maintenance_incidents' | ||
end | ||
|
||
class MultipleIncidentCounters < ActiveRecord::Migration | ||
def self.up | ||
create_table :incident_updateinfo_counter_values do |t| | ||
t.references :updateinfo_counter, null: false | ||
t.references :project, null: false | ||
t.integer :value, null: false | ||
t.datetime :released_at, null: false | ||
end | ||
add_index :incident_updateinfo_counter_values, [:updateinfo_counter_id, :project_id], :name => "uniq_id_index" | ||
execute("alter table incident_updateinfo_counter_values add foreign key (project_id) references projects(id)") | ||
|
||
rename_table :updateinfo_counter, :updateinfo_counters | ||
|
||
TempMI.all.each do |mi| | ||
value = mi.counter | ||
next unless value | ||
|
||
mp = mi.maintenance_db_project | ||
|
||
# there could have been just one so far | ||
uc = UpdateinfoCounter.find_by_maintenance_db_project( mp ).first | ||
|
||
IncidentUpdateinfoCounterValue.create(updateinfo_counter: uc, project: mp, value: value) | ||
end | ||
|
||
remove_column :maintenance_incidents, :counter | ||
remove_column :maintenance_incidents, :name | ||
end | ||
|
||
def self.down | ||
drop_table :incident_updateinfo_counter_values | ||
add_column :maintenance_incidents, :counter, :integer | ||
add_column :maintenance_incidents, :name, :string | ||
rename_table :updateinfo_counters, :updateinfo_counter | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters