b0b816b0ee
- migrations/0001_init: 全部核心表(product/food_detail/product_msrp/product_source/brand/manufacturer/category/category_schema/unit/attribute_definition/product_image/merge_log) + 索引(gtin唯一/name trigram/JSONB GIN/category ltree/tsvector) + tsvector/updated_at 触发器 - 0002_seed_units: 单位字典(与 units.py 一致, 含中文别名) + 常用营养参数定义 - 0003_seed_categories: 食品品类骨架(GS1 GPC 映射 + 自建中文树, ltree) + 品类参数模板(营养基准 per_100g/ml) - CI 增加 migrations job: 用 postgres service 跑 migrate up + down 验证可逆 - 本地实跑 up/down/re-up 全部通过 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
30 lines
2.1 KiB
SQL
30 lines
2.1 KiB
SQL
-- Unit dictionary seed. Keep factors aligned with ingestion/opengoods/units.py.
|
|
|
|
INSERT INTO unit (code, dimension, canonical, to_canonical_factor, aliases, display) VALUES
|
|
('mg', 'mass', 'g', 0.001, ARRAY['毫克'], 'mg'),
|
|
('g', 'mass', 'g', 1, ARRAY['克','gram','grams'], 'g'),
|
|
('kg', 'mass', 'g', 1000, ARRAY['kgs','千克','公斤'], 'kg'),
|
|
('ml', 'volume', 'ml', 1, ARRAY['毫升','milliliter'], 'mL'),
|
|
('cl', 'volume', 'ml', 10, ARRAY['厘升'], 'cL'),
|
|
('l', 'volume', 'ml', 1000, ARRAY['L','升','litre','liter'], 'L'),
|
|
('kj', 'energy', 'kJ', 1, ARRAY['kJ','千焦'], 'kJ'),
|
|
('kcal', 'energy', 'kJ', 4.184, ARRAY['千卡','大卡'], 'kcal'),
|
|
('pct', 'ratio', 'pct', 1, ARRAY['%','percent','百分比'], '%'),
|
|
('unit', 'count', 'unit',1, ARRAY['个','件','pcs','piece'], '个'),
|
|
('mm', 'length', 'mm', 1, ARRAY['毫米'], 'mm'),
|
|
('cm', 'length', 'mm', 10, ARRAY['厘米'], 'cm'),
|
|
('day', 'duration', 'day', 1, ARRAY['天','日','days'], 'day')
|
|
ON CONFLICT (code) DO NOTHING;
|
|
|
|
-- A few common food attribute definitions referencing the unit dictionary.
|
|
INSERT INTO attribute_definition (key, label_zh, label_en, dimension, default_unit, aliases) VALUES
|
|
('energy', '能量', 'Energy', 'energy', 'kj', ARRAY['energy_kj']),
|
|
('proteins', '蛋白质', 'Proteins', 'mass', 'g', ARRAY['protein']),
|
|
('fat', '脂肪', 'Fat', 'mass', 'g', ARRAY['fats']),
|
|
('saturated_fat', '饱和脂肪','Saturated fat','mass', 'g', ARRAY['saturated-fat']),
|
|
('carbohydrates', '碳水化合物','Carbohydrates','mass', 'g', ARRAY['carbs']),
|
|
('sugars', '糖', 'Sugars', 'mass', 'g', ARRAY['sugar']),
|
|
('salt', '盐', 'Salt', 'mass', 'g', ARRAY['sodium_salt']),
|
|
('net_content', '净含量', 'Net content', NULL, NULL, ARRAY['quantity'])
|
|
ON CONFLICT (key) DO NOTHING;
|