Module: ChronoModel::Utilities

Included in:
ChronoModel
Defined in:
lib/chrono_model/utils.rb

Instance Method Summary collapse

Instance Method Details

#amend_period!(hid, from, to) ⇒ Object

Amends the given history item setting a different period. Useful when migrating from legacy systems.


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/chrono_model/utils.rb', line 47

def amend_period!(hid, from, to)
  unless [from, to].any? {|ts| ts.respond_to?(:zone) && ts.zone == 'UTC'}
    raise 'Can amend history only with UTC timestamps'
  end

  connection.execute %[
    UPDATE #{quoted_table_name}
       SET "validity" = tsrange(#{connection.quote(from)}, #{connection.quote(to)}),
           "recorded_at" = #{connection.quote(from)}
     WHERE "hid" = #{hid.to_i}
  ]
end

#chrono?Boolean

Returns true if this model is backed by a temporal table, false otherwise.

Returns:

  • (Boolean)

63
64
65
# File 'lib/chrono_model/utils.rb', line 63

def chrono?
  connection.is_chrono?(table_name)
end