Module: Skr::DB::TableFields

Defined in:
lib/skr/db/migration_helpers.rb

Instance Method Summary collapse

Instance Method Details

#skr_code_identifierObject



9
10
11
12
# File 'lib/skr/db/migration_helpers.rb', line 9

def skr_code_identifier
    column( :code, :string,  :null=>false )
    skr_extra_indexes['code'] = {}
end

#skr_currency(names, options) ⇒ Object



33
34
35
36
37
# File 'lib/skr/db/migration_helpers.rb', line 33

def skr_currency( names, options )
    options[ :precision ] ||= 15
    options[ :scale ]     ||= 2
    column( names, :decimal, options )
end

#skr_extra_indexesObject



59
60
61
# File 'lib/skr/db/migration_helpers.rb', line 59

def skr_extra_indexes
    @skr_extra_indexs ||= {}
end

#skr_foreign_keysObject



55
56
57
# File 'lib/skr/db/migration_helpers.rb', line 55

def skr_foreign_keys
    @skr_foreign_keys ||= {}
end

#skr_reference(to_table, *args) ⇒ Object

An skr_reference combines a belongs_to / has_one column with a postgresql foreign key reference.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/skr/db/migration_helpers.rb', line 41

def skr_reference( to_table, *args )
    options = args.extract_options!

    options[:column] ||= to_table.to_s + '_id'

    column( options[:column], :integer, :null=>options[:null] || false )
    to_table = options[:to_table] if options.has_key? :to_table

    if options[:single]
        to_table = to_table.to_s.pluralize
    end
    skr_foreign_keys[ to_table.to_sym ] = options
end

#skr_stateObject



19
20
21
# File 'lib/skr/db/migration_helpers.rb', line 19

def skr_state
    column( :state, :integer, null: false, default: 0, limit: 2 )
end

#skr_track_modifications(create_only: false) ⇒ Object

track modifications



24
25
26
27
28
29
30
31
# File 'lib/skr/db/migration_helpers.rb', line 24

def skr_track_modifications( create_only: false )
    column( :created_at, :datetime,   :null=>false )
    column( :created_by_id, :integer, :null=>false )
    unless create_only
        column( :updated_at, :datetime,   :null=>false )
        column( :updated_by_id, :integer, :null=>false )
    end
end

#skr_visible_idObject



14
15
16
17
# File 'lib/skr/db/migration_helpers.rb', line 14

def skr_visible_id
    column( :visible_id, :string,  :null=>false )
    skr_extra_indexes['visible_id'] = {}
end