forked from fixin.me/fixin.me
Auto-create check constraints for text fields with limit
Move column defaults from migration strategy to migrations. Compact index creation inside migrations. Disable database schema generation.
This commit is contained in:
@@ -2,14 +2,17 @@ class CreateUnits < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :units do |t|
|
||||
t.references :user, foreign_key: {on_delete: :cascade}
|
||||
t.string :symbol, null: false, limit: 15
|
||||
t.text :description
|
||||
t.string :symbol, null: false, limit: 2**4
|
||||
t.text :description, limit: 2**16
|
||||
t.float :multiplier, null: false, limit: Float::MANT_DIG, default: 1.0
|
||||
t.references :base, foreign_key: {to_table: :units, on_delete: :cascade}
|
||||
|
||||
t.timestamps
|
||||
|
||||
# Constraints:
|
||||
# * symbol has to be unique
|
||||
t.index [:user_id, :symbol], unique: true
|
||||
# * unit has to belong to the same user as quantity (used by :readouts)
|
||||
t.index [:id, :user_id], unique: true
|
||||
end
|
||||
add_index :units, [:user_id, :symbol]
|
||||
add_index :units, [:id, :user_id]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user