Module: Snaptime::MigrationHelpers::SchemaStatements::Table

Defined in:
lib/snaptime/migration_helpers.rb

Instance Method Summary collapse

Instance Method Details

#unversionizeObject



35
36
37
38
39
40
# File 'lib/snaptime/migration_helpers.rb', line 35

def unversionize
  remove :natural_id
  remove :valid_from
  remove :valid_to
  remove :deleted
end

#versionizeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/snaptime/migration_helpers.rb', line 15

def versionize
  column :natural_id, :integer
  column :valid_from, :timestamp, precision: 3
  column :valid_to, :timestamp, precision: 3
  column :deleted, :boolean, null: false, default: 0

  index :natural_id
  index :valid_from
  index :valid_to

  index %i(natural_id valid_to), unique: true

  @base.execute %(
    ALTER TABLE "#{name.to_s.upcase}"
    ADD CONSTRAINT "#{name.to_s.upcase}_VCVD" CHECK (
      VALID_TO IS NULL OR VALID_FROM <= VALID_TO
    )
  )
end