Module: ChronoModel::Utilities

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
# 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)})
     WHERE "hid" = #{hid.to_i}
  ]
end

#chrono?Boolean

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

Returns:

  • (Boolean)


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

def chrono?
  connection.is_chrono?(table_name)
end