Module: Skr::Core::DB::TableFields

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

Instance Method Summary collapse

Instance Method Details

#skr_code_identifierObject



9
10
11
12
# File 'lib/skr/core/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



31
32
33
34
35
# File 'lib/skr/core/db/migration_helpers.rb', line 31

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

#skr_extra_indexesObject



57
58
59
# File 'lib/skr/core/db/migration_helpers.rb', line 57

def skr_extra_indexes
    @skr_extra_indexs ||= {}
end

#skr_foreign_keysObject



53
54
55
# File 'lib/skr/core/db/migration_helpers.rb', line 53

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.



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

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_track_modifications(create_only: false) ⇒ Object

track modifications



22
23
24
25
26
27
28
29
# File 'lib/skr/core/db/migration_helpers.rb', line 22

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
18
19
# File 'lib/skr/core/db/migration_helpers.rb', line 14

def skr_visible_id
    column( :visible_id, :integer,  :null=>false )
    skr_extra_indexes['visible_id'] = {
        function: 'CAST(visible_id AS VARCHAR)'
    }
end