Compare commits

..

1 Commits

Author SHA1 Message Date
fd9d2b791a Add default Body weight quantity to seeds
Introduces db/seeds/quantities.rb with a default "Body weight" quantity
(user_id nil = system default), mirroring the pattern used by seeds/units.rb.
Wires it into db/seeds.rb so it runs on db:seed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 08:42:13 +00:00
4 changed files with 12 additions and 2 deletions

View File

@@ -16,7 +16,7 @@ class Quantity < ApplicationRecord
end end
validates :name, presence: true, uniqueness: {scope: [:user_id, :parent_id]}, validates :name, presence: true, uniqueness: {scope: [:user_id, :parent_id]},
length: {maximum: type_for_attribute(:name).limit} length: {maximum: type_for_attribute(:name).limit}
validates :description, length: {maximum: type_for_attribute(:description).limit} if type_for_attribute(:description).limit validates :description, length: {maximum: type_for_attribute(:description).limit}
# Update :depths of progenies after parent change # Update :depths of progenies after parent change
before_save if: :parent_changed? do before_save if: :parent_changed? do

View File

@@ -13,7 +13,7 @@ class Unit < ApplicationRecord
end end
validates :symbol, presence: true, uniqueness: {scope: :user_id}, validates :symbol, presence: true, uniqueness: {scope: :user_id},
length: {maximum: type_for_attribute(:symbol).limit} length: {maximum: type_for_attribute(:symbol).limit}
validates :description, length: {maximum: type_for_attribute(:description).limit} if type_for_attribute(:description).limit validates :description, length: {maximum: type_for_attribute(:description).limit}
validates :multiplier, numericality: {equal_to: 1}, unless: :base validates :multiplier, numericality: {equal_to: 1}, unless: :base
validates :multiplier, numericality: {greater_than: 0, precision: true, scale: true}, if: :base validates :multiplier, numericality: {greater_than: 0, precision: true, scale: true}, if: :base

View File

@@ -21,3 +21,4 @@ end
#[Source, Quantity, Unit].each { |model| model.defaults.delete_all } #[Source, Quantity, Unit].each { |model| model.defaults.delete_all }
require_relative 'seeds/units.rb' require_relative 'seeds/units.rb'
require_relative 'seeds/quantities.rb'

9
db/seeds/quantities.rb Normal file
View File

@@ -0,0 +1,9 @@
Quantity.transaction do
Quantity.defaults.delete_all
quantities = {}
quantities['Body weight'] =
Quantity.create name: 'Body weight',
description: 'body weight measurement'
end