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:
2026-11-26 02:32:09 +01:00
parent 74f9a09098
commit b6d2c19b0b
9 changed files with 148 additions and 210 deletions
+8 -5
View File
@@ -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