-
Notifications
You must be signed in to change notification settings - Fork 21
Backfilling history
Paolo Zaccagnini edited this page Dec 12, 2017
·
1 revision
The basic workflow is:
Have a sorted array like this:
data = [
{value: 1, from: '2010-01-01 00:00:00', to: '2011-01-01 00:00:00'},
{value: 2, from: '2011-01-01 00:00:00', to: '2012-01-01 00:00:00'},
{value: 3, from: '2012-01-01 00:00:00', to: '2013-01-01 00:00:00'},
{value: 4, from: '2013-01-01 00:00:00', to: '2014-01-01 00:00:00'},
{value: 5, from: '2014-01-01 00:00:00', to: '2015-01-01 00:00:00'}
{value: 6, from: '2015-01-01 00:00:00', to: nil}
]
Wipe out the tables
Item.delete_all
Item::History.delete_all
Fill from the past:
record = Item.new
data.each do |d|
record.value = d[:value]
record.save!
h = record.history.first
h.class.amend_period!(h.hid, d[:from], d[:to])
end