Module: Ddb::SixArm::MigrationHelper::InstanceMethods
- Defined in:
- lib/sixarm_ruby_migration_helper_extensions.rb
Instance Method Summary collapse
- #altitude(column_name = :altitude) ⇒ Object
-
#auditstamps ⇒ Object
auditstamps: we like to track what’s happening to a row, by using typical Rails timestamps and then some more.
-
#dba ⇒ Object
Database administration.
- #depth(column_name = :depth) ⇒ Object
- #elevation(column_name = :elevation) ⇒ Object
-
#email(column_name = :email) ⇒ Object
email: string limit is 320 because the email spec has pieces that total to 320, though then trims the limit to 254.
-
#freebase(column_name = :freebase) ⇒ Object
Vendor.
- #geolocation ⇒ Object
-
#height(column_name = :height) ⇒ Object
Size.
-
#hostname(column_name = :hostname) ⇒ Object
hostname: POSIX standard is not to exceed 255 bytes.
-
#iso_3166_1_alpha_2(column_name = :iso_3166_1_alpha_2) ⇒ Object
ISO 3166-1 alpha-2 - two-letter country codes which are also used to create the ISO 3166-2 country subdivision codes and the Internet country code top-level domains.
-
#iso_3166_1_alpha_3(column_name = :iso_3166_1_alpha_3) ⇒ Object
ISO 3166-1 alpha-3 – three-letter country codes which may allow a better visual association between the codes and the country names than the 3166-1 alpha-2 codes.
-
#iso_3166_1_numeric(column_name = :iso_3166_1_numeric) ⇒ Object
ISO 3166-1 numeric – three-digit country codes which are identical to those developed and maintained by the United Nations Statistics Division, with the advantage of script (writing system) independence, and hence useful for people or systems using non-Latin scripts.
-
#latitude(column_name = :latitude) ⇒ Object
Geolocation.
- #length(column_name = :length) ⇒ Object
-
#lock_version(column_name = :lock_version) ⇒ Object
lock_version: Rails row locking using either optimistic locking or pessimistic locking.
- #longitude(column_name = :longitude) ⇒ Object
- #mass(column_name = :mass) ⇒ Object
-
#parent_id(column_name = :parent_id) ⇒ Object
parent_id: we sometimes use parent-child relationships, where ‘parent_id` points to the parent row.
-
#phone(column_name = :phone) ⇒ Object
phone: string limit is 75 because that’s our arbitrary limit, and long enough for international numbers and extensions.
-
#position(column_name = :position) ⇒ Object
position: we sometimes like to use ordered lists, where the ‘position` is the list position.
-
#state(column_name = :state) ⇒ Object
state: we sometimes like to use state machines, where the ‘state` is an integer enumeration.
-
#timestamp_string(column_name = :timestamp_string) ⇒ Object
timestamp_string: timestamp strings are good for e.g.
-
#type(column_name = :type) ⇒ Object
type: Rails single table inheritance (STI) uses a magic field name ‘type`.
-
#uri(column_name = :uri) ⇒ Object
uri: string is unlimited.
-
#uuid_string(column_name = :uuid_string) ⇒ Object
uuid_string: we sometimes like to use UUID strings; for efficiency, we suggest using a database-native format.
- #width(column_name = :width) ⇒ Object
-
#zid_string(column_name = :zid_string) ⇒ Object
zid_string: we sometimes like to use ZID strings, similar to UUID stings; for efficiency, we suggest using a database-native format.
Instance Method Details
#altitude(column_name = :altitude) ⇒ Object
73 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 73 def altitude(column_name=:altitude) column(column_name, :decimal, precision: 13, scale: 10); end |
#auditstamps ⇒ Object
auditstamps: we like to track what’s happening to a row, by using typical Rails timestamps and then some more.
178 179 180 181 182 183 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 178 def auditstamps column(:created_at, :datetime); column(:created_by, :integer); column(:updated_at, :datetime); column(:updated_by, :integer); column(:proofed_at, :datetime); column(:proofed_by, :integer); column(:retired_at, :datetime); column(:retired_by, :integer); end |
#dba ⇒ Object
Database administration
We build many Rails apps and we like to add some columns that help with database administration and easy growth.
We like to add these columns during setup, even if we don’t use them, because they make syncronization easy, and they work with some of our data auditing shared code.
Use what you like, customize as you like, YMMV, etc.
197 198 199 200 201 202 203 204 205 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 197 def dba uuid_string auditstamps lock_version state parent_id position type end |
#depth(column_name = :depth) ⇒ Object
62 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 62 def depth(column_name=:depth) column(column_name, :decimal, precision: 13, scale: 10) end |
#elevation(column_name = :elevation) ⇒ Object
74 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 74 def elevation(column_name=:elevation) column(column_name, :decimal, precision: 13, scale: 10); end |
#email(column_name = :email) ⇒ Object
email: string limit is 320 because the email spec has pieces that total to 320, though then trims the limit to 254.
27 28 29 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 27 def email(column_name=:email) column(column_name, :string, limit: 320) end |
#freebase(column_name = :freebase) ⇒ Object
Vendor
213 214 215 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 213 def freebase(column_name=:freebase) column(column_name, :string) end |
#geolocation ⇒ Object
76 77 78 79 80 81 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 76 def geolocation latitude longitude altitude elevation end |
#height(column_name = :height) ⇒ Object
Size
59 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 59 def height(column_name=:height) column(column_name, :decimal, precision: 13, scale: 10) end |
#hostname(column_name = :hostname) ⇒ Object
hostname: POSIX standard is not to exceed 255 bytes.
49 50 51 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 49 def hostname(column_name=:hostname) column(column_name, :string, limit: 255) end |
#iso_3166_1_alpha_2(column_name = :iso_3166_1_alpha_2) ⇒ Object
ISO 3166-1 alpha-2 - two-letter country codes which are also used to create the ISO 3166-2 country subdivision codes and the Internet country code top-level domains.
90 91 92 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 90 def iso_3166_1_alpha_2(column_name=:iso_3166_1_alpha_2) column(column_name, :string, limit: 2) end |
#iso_3166_1_alpha_3(column_name = :iso_3166_1_alpha_3) ⇒ Object
ISO 3166-1 alpha-3 – three-letter country codes which may allow a better visual association between the codes and the country names than the 3166-1 alpha-2 codes.
95 96 97 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 95 def iso_3166_1_alpha_3(column_name=:iso_3166_1_alpha_3) column(column_name, :string, limit: 3) end |
#iso_3166_1_numeric(column_name = :iso_3166_1_numeric) ⇒ Object
ISO 3166-1 numeric – three-digit country codes which are identical to those developed and maintained by the United Nations Statistics Division, with the advantage of script (writing system) independence, and hence useful for people or systems using non-Latin scripts.
100 101 102 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 100 def iso_3166_1_numeric(column_name=:iso_3166_1_numeric) column(column_name, :string, limit: 3) end |
#latitude(column_name = :latitude) ⇒ Object
Geolocation
71 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 71 def latitude(column_name=:latitude) column(column_name, :decimal, precision: 13, scale: 10); end |
#length(column_name = :length) ⇒ Object
60 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 60 def length(column_name=:length) column(column_name, :decimal, precision: 13, scale: 10) end |
#lock_version(column_name = :lock_version) ⇒ Object
lock_version: Rails row locking using either optimistic locking or pessimistic locking.
162 163 164 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 162 def lock_version(column_name=:lock_version) column(column_name, :integer) end |
#longitude(column_name = :longitude) ⇒ Object
72 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 72 def longitude(column_name=:longitude) column(column_name, :decimal, precision: 13, scale: 10); end |
#mass(column_name = :mass) ⇒ Object
63 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 63 def mass(column_name=:mass) column(column_name, :decimal, precision: 13, scale: 10) end |
#parent_id(column_name = :parent_id) ⇒ Object
parent_id: we sometimes use parent-child relationships, where ‘parent_id` points to the parent row.
138 139 140 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 138 def parent_id(column_name=:parent_id) column(column_name, :integer) end |
#phone(column_name = :phone) ⇒ Object
phone: string limit is 75 because that’s our arbitrary limit, and long enough for international numbers and extensions.
35 36 37 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 35 def phone(column_name=:phone) column(column_name, :string) end |
#position(column_name = :position) ⇒ Object
position: we sometimes like to use ordered lists, where the ‘position` is the list position.
146 147 148 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 146 def position(column_name=:position) column(column_name, :integer) end |
#state(column_name = :state) ⇒ Object
state: we sometimes like to use state machines, where the ‘state` is an integer enumeration.
154 155 156 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 154 def state(column_name=:state) column(column_name, :integer) end |
#timestamp_string(column_name = :timestamp_string) ⇒ Object
timestamp_string: timestamp strings are good for e.g. log reports; our format has a max length of “YYYY-DD-MMTHH:MM:SS.NNNNNNNNN+HH:MM”.
114 115 116 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 114 def (column_name=:timestamp_string) column(column_name, :string, limit: 35) end |
#type(column_name = :type) ⇒ Object
type: Rails single table inheritance (STI) uses a magic field name ‘type`.
170 171 172 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 170 def type(column_name=:type) column(column_name, :string) end |
#uri(column_name = :uri) ⇒ Object
uri: string is unlimited.
42 43 44 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 42 def uri(column_name=:uri) column(column_name, :string) end |
#uuid_string(column_name = :uuid_string) ⇒ Object
uuid_string: we sometimes like to use UUID strings; for efficiency, we suggest using a database-native format.
122 123 124 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 122 def uuid_string(column_name=:uuid_string) column(column_name, :string, limit: 36) end |
#width(column_name = :width) ⇒ Object
61 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 61 def width(column_name=:width) column(column_name, :decimal, precision: 13, scale: 10) end |
#zid_string(column_name = :zid_string) ⇒ Object
zid_string: we sometimes like to use ZID strings, similar to UUID stings; for efficiency, we suggest using a database-native format.
130 131 132 |
# File 'lib/sixarm_ruby_migration_helper_extensions.rb', line 130 def zid_string(column_name=:zid_string) column(column_name, :string, limit: 36) end |