Module: Skr::DB::TableFields
- Defined in:
- lib/skr/db/migration_helpers.rb
Instance Method Summary collapse
- #skr_code_identifier ⇒ Object
- #skr_currency(names, options) ⇒ Object
- #skr_extra_indexes ⇒ Object
- #skr_foreign_keys ⇒ Object
-
#skr_reference(to_table, *args) ⇒ Object
An skr_reference combines a belongs_to / has_one column with a postgresql foreign key reference.
- #skr_state ⇒ Object
-
#skr_track_modifications(create_only: false) ⇒ Object
track modifications.
- #skr_visible_id ⇒ Object
Instance Method Details
#skr_code_identifier ⇒ Object
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, ) [ :precision ] ||= 15 [ :scale ] ||= 2 column( names, :decimal, ) end |
#skr_extra_indexes ⇒ Object
59 60 61 |
# File 'lib/skr/db/migration_helpers.rb', line 59 def skr_extra_indexes @skr_extra_indexs ||= {} end |
#skr_foreign_keys ⇒ Object
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 ) = args. [:column] ||= to_table.to_s + '_id' column( [:column], :integer, :null=>[:null] || false ) to_table = [:to_table] if .has_key? :to_table if [:single] to_table = to_table.to_s.pluralize end skr_foreign_keys[ to_table.to_sym ] = end |
#skr_state ⇒ Object
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_id ⇒ Object
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 |