Moved defaults into separate migration
This commit is contained in:
parent
dc9ebb36f6
commit
0e5a53b4b9
51
db/migrate/001_create_schema.rb
Normal file
51
db/migrate/001_create_schema.rb
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
class CreateSchema < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :units do |t|
|
||||||
|
t.references :project
|
||||||
|
t.string :name
|
||||||
|
t.string :shortname
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :quantities do |t|
|
||||||
|
t.references :project
|
||||||
|
t.integer :domain
|
||||||
|
t.string :name
|
||||||
|
t.string :formula
|
||||||
|
t.string :description
|
||||||
|
t.boolean :primary
|
||||||
|
# fields for awesome_nested_set
|
||||||
|
t.references :parent
|
||||||
|
t.integer :lft, :null => false, :index => true
|
||||||
|
t.integer :rgt, :null => false, :index => true
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :sources do |t|
|
||||||
|
t.references :project
|
||||||
|
t.string :name
|
||||||
|
t.text :description
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :ingredients do |t|
|
||||||
|
t.references :project
|
||||||
|
t.string :name
|
||||||
|
t.decimal :ref_amount, precision: 12, scale: 6
|
||||||
|
t.references :ref_unit
|
||||||
|
t.integer :group
|
||||||
|
t.references :source
|
||||||
|
t.string :source_ident
|
||||||
|
t.boolean :hidden
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :nutrients do |t|
|
||||||
|
t.references :ingredient
|
||||||
|
t.references :quantity
|
||||||
|
t.decimal :amount, precision: 12, scale: 6
|
||||||
|
t.references :unit
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,183 +0,0 @@
|
|||||||
class CreateUnits < ActiveRecord::Migration
|
|
||||||
def change
|
|
||||||
create_table :units do |t|
|
|
||||||
t.references :project
|
|
||||||
t.string :name
|
|
||||||
t.string :shortname
|
|
||||||
t.timestamps null: false
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table :quantities do |t|
|
|
||||||
t.references :project
|
|
||||||
t.integer :domain
|
|
||||||
t.string :name
|
|
||||||
t.string :formula
|
|
||||||
t.string :description
|
|
||||||
t.boolean :primary
|
|
||||||
# fields for awesome_nested_set
|
|
||||||
t.references :parent
|
|
||||||
t.integer :lft, :null => false, :index => true
|
|
||||||
t.integer :rgt, :null => false, :index => true
|
|
||||||
t.timestamps null: false
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table :sources do |t|
|
|
||||||
t.references :project
|
|
||||||
t.string :name
|
|
||||||
t.text :description
|
|
||||||
t.timestamps null: false
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table :ingredients do |t|
|
|
||||||
t.references :project
|
|
||||||
t.string :name
|
|
||||||
t.decimal :ref_amount, precision: 12, scale: 6
|
|
||||||
t.references :ref_unit
|
|
||||||
t.integer :group
|
|
||||||
t.references :source
|
|
||||||
t.string :source_ident
|
|
||||||
t.boolean :hidden
|
|
||||||
t.timestamps null: false
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table :nutrients do |t|
|
|
||||||
t.references :ingredient
|
|
||||||
t.references :quantity
|
|
||||||
t.decimal :amount, precision: 12, scale: 6
|
|
||||||
t.references :unit
|
|
||||||
t.timestamps null: false
|
|
||||||
end
|
|
||||||
|
|
||||||
reversible do |dir|
|
|
||||||
dir.up do
|
|
||||||
Unit.create project: nil, shortname: "g", name: "gram"
|
|
||||||
Unit.create project: nil, shortname: "mg", name: "milligram"
|
|
||||||
Unit.create project: nil, shortname: "ug", name: "microgram"
|
|
||||||
Unit.create project: nil, shortname: "kg", name: "kilogram"
|
|
||||||
Unit.create project: nil, shortname: "kcal", name: "kilocalorie"
|
|
||||||
Unit.create project: nil, shortname: "%", name: "percent"
|
|
||||||
|
|
||||||
# https://www.fsai.ie/uploadedFiles/Consol_Reg1169_2011.pdf
|
|
||||||
# https://www.fsai.ie/legislation/food_legislation/food_information_fic/nutrition_labelling.html
|
|
||||||
e = Quantity.create project: nil, domain: :diet, parent: nil, name: "Energy",
|
|
||||||
description: "Total energy", primary: true
|
|
||||||
|
|
||||||
Quantity.create project: nil, domain: :diet, parent: nil, name: "Proteins",
|
|
||||||
description: "Total amount of proteins", primary: true
|
|
||||||
|
|
||||||
f = Quantity.create project: nil, domain: :diet, parent: nil, name: "Fats",
|
|
||||||
description: "Total lipids, including phospholipids", primary: true
|
|
||||||
f1 = Quantity.create project: nil, domain: :diet, parent: f, name: "Fatty acids",
|
|
||||||
description: ""
|
|
||||||
f2 = Quantity.create project: nil, domain: :diet, parent: f1, name: "Saturated",
|
|
||||||
description: "Fatty acids without double bond"
|
|
||||||
f3 = Quantity.create project: nil, domain: :diet, parent: f1, name: "Unsaturated",
|
|
||||||
description: ""
|
|
||||||
f4 = Quantity.create project: nil, domain: :diet, parent: f3, name: "Monounsaturated",
|
|
||||||
description: "Fatty acids with one cis double bond"
|
|
||||||
f5 = Quantity.create project: nil, domain: :diet, parent: f3, name: "Polyunsaturated",
|
|
||||||
description: "Fatty acids with two or more cis, cis-methylene interrupted" \
|
|
||||||
" double bonds; PUFA"
|
|
||||||
f6 = Quantity.create project: nil, domain: :diet, parent: f3, name: "Trans",
|
|
||||||
description: "Fatty acids with at least one non-conjugated C-C double bond in the" \
|
|
||||||
" trans configuration"
|
|
||||||
f7 = Quantity.create project: nil, domain: :diet, parent: f5, name: "Omega-3 (n-3)",
|
|
||||||
description: ""
|
|
||||||
f8 = Quantity.create project: nil, domain: :diet, parent: f5, name: "Omega-6 (n-6)",
|
|
||||||
description: ""
|
|
||||||
f9 = Quantity.create project: nil, domain: :diet, parent: f7, name: "ALA 18:3(n-3)",
|
|
||||||
description: "alpha-Linolenic acid"
|
|
||||||
f10 = Quantity.create project: nil, domain: :diet, parent: f7, name: "EPA 20:5(n-3)",
|
|
||||||
description: "Eicosapentaenoic acid; also icosapentaenoic acid"
|
|
||||||
f11 = Quantity.create project: nil, domain: :diet, parent: f7, name: "DHA 22:6(n-3)",
|
|
||||||
description: "Docosahexaenoic acid"
|
|
||||||
|
|
||||||
c1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Carbohydrates",
|
|
||||||
description: "Total amount of carbohydrates", primary: true
|
|
||||||
c2 = Quantity.create project: nil, domain: :diet, parent: c1, name: "Digestible",
|
|
||||||
description: ""
|
|
||||||
c3 = Quantity.create project: nil, domain: :diet, parent: c2, name: "Sugars",
|
|
||||||
description: "Monosaccharides and disaccharides, excluding polyols"
|
|
||||||
c4 = Quantity.create project: nil, domain: :diet, parent: c3, name: "Monosaccharides",
|
|
||||||
description: ""
|
|
||||||
c5 = Quantity.create project: nil, domain: :diet, parent: c4, name: "Glucose",
|
|
||||||
description: ""
|
|
||||||
c6 = Quantity.create project: nil, domain: :diet, parent: c4, name: "Fructose",
|
|
||||||
description: ""
|
|
||||||
c7 = Quantity.create project: nil, domain: :diet, parent: c3, name: "Disaccharides",
|
|
||||||
description: ""
|
|
||||||
c8 = Quantity.create project: nil, domain: :diet, parent: c7, name: "Sucrose",
|
|
||||||
description: ""
|
|
||||||
c9 = Quantity.create project: nil, domain: :diet, parent: c7, name: "Lactose",
|
|
||||||
description: ""
|
|
||||||
c10 = Quantity.create project: nil, domain: :diet, parent: c2, name: "Polyols",
|
|
||||||
description: "Alcohols containing more than 2 hydroxyl groups"
|
|
||||||
c11 = Quantity.create project: nil, domain: :diet, parent: c2,
|
|
||||||
name: "Polysaccharides", description: ""
|
|
||||||
c12 = Quantity.create project: nil, domain: :diet, parent: c11, name: "Starch",
|
|
||||||
description: ""
|
|
||||||
c13 = Quantity.create project: nil, domain: :diet, parent: c1, name: "Indigestible",
|
|
||||||
description: ""
|
|
||||||
c14 = Quantity.create project: nil, domain: :diet, parent: c13, name: "Fibre",
|
|
||||||
description: "Carbohydrate polymers with 3 or more monomeric units, which are" \
|
|
||||||
" neither digested nor absorbed in the human small intestine"
|
|
||||||
|
|
||||||
m1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Minerals",
|
|
||||||
description: ""
|
|
||||||
m2 = Quantity.create project: nil, domain: :diet, parent: m1, name: "Salt",
|
|
||||||
description: "Sodium chloride"
|
|
||||||
|
|
||||||
v1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Vitamins",
|
|
||||||
description: ""
|
|
||||||
v2 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin A",
|
|
||||||
description: ""
|
|
||||||
v3 = Quantity.create project: nil, domain: :diet, parent: v2, name: "Retinol (A1)",
|
|
||||||
description: ""
|
|
||||||
v4 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Provitamin A",
|
|
||||||
description: ""
|
|
||||||
v5 = Quantity.create project: nil, domain: :diet, parent: v4, name: "beta-Carotene",
|
|
||||||
description: ""
|
|
||||||
v6 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin B",
|
|
||||||
description: ""
|
|
||||||
v7 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Thiamine (B1)",
|
|
||||||
description: ""
|
|
||||||
v8 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Riboflavin (B2)",
|
|
||||||
description: "Vitamin G"
|
|
||||||
v9 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Vitamin B3",
|
|
||||||
description: "Vitamin PP"
|
|
||||||
v10 = Quantity.create project: nil, domain: :diet, parent: v9, name: "Niacin",
|
|
||||||
description: "Nicotinic acid"
|
|
||||||
v11 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Vitamin B5",
|
|
||||||
description: "Pantothenic acid"
|
|
||||||
v12 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Vitamin B6",
|
|
||||||
description: ""
|
|
||||||
v13 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Biotin (B7)",
|
|
||||||
description: "Vitamin H, also coenzyme R"
|
|
||||||
v14 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Folate",
|
|
||||||
description: "Includes: folic acid, folacin and vitamin B9"
|
|
||||||
v15 = Quantity.create project: nil, domain: :diet, parent: v14, name: "Vitamin B9",
|
|
||||||
description: ""
|
|
||||||
v16 = Quantity.create project: nil, domain: :diet, parent: v6,
|
|
||||||
name: "Cobalamin (B12)", description: ""
|
|
||||||
v17 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin C",
|
|
||||||
description: ""
|
|
||||||
v18 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin D",
|
|
||||||
description: "Calciferol"
|
|
||||||
v19 = Quantity.create project: nil, domain: :diet, parent: v18,
|
|
||||||
name: "Cholecalciferol (D3)", description: ""
|
|
||||||
v20 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin E",
|
|
||||||
description: ""
|
|
||||||
v21 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin K",
|
|
||||||
description: ""
|
|
||||||
|
|
||||||
Source.create project: nil, name: "nutrition label",
|
|
||||||
description: "nutrition facts taken from package nutrition label"
|
|
||||||
end
|
|
||||||
dir.down do
|
|
||||||
Unit.where(project: nil).delete_all
|
|
||||||
Quantity.where(project: nil).delete_all
|
|
||||||
Source.where(project: nil).delete_all
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
133
db/migrate/002_load_defaults.rb
Normal file
133
db/migrate/002_load_defaults.rb
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
class LoadDefaults < ActiveRecord::Migration
|
||||||
|
reversible do |dir|
|
||||||
|
dir.up do
|
||||||
|
Unit.create project: nil, shortname: "g", name: "gram"
|
||||||
|
Unit.create project: nil, shortname: "mg", name: "milligram"
|
||||||
|
Unit.create project: nil, shortname: "ug", name: "microgram"
|
||||||
|
Unit.create project: nil, shortname: "kg", name: "kilogram"
|
||||||
|
Unit.create project: nil, shortname: "kcal", name: "kilocalorie"
|
||||||
|
Unit.create project: nil, shortname: "%", name: "percent"
|
||||||
|
|
||||||
|
# https://www.fsai.ie/uploadedFiles/Consol_Reg1169_2011.pdf
|
||||||
|
# https://www.fsai.ie/legislation/food_legislation/food_information_fic/nutrition_labelling.html
|
||||||
|
e = Quantity.create project: nil, domain: :diet, parent: nil, name: "Energy",
|
||||||
|
description: "Total energy", primary: true
|
||||||
|
|
||||||
|
Quantity.create project: nil, domain: :diet, parent: nil, name: "Proteins",
|
||||||
|
description: "Total amount of proteins", primary: true
|
||||||
|
|
||||||
|
f = Quantity.create project: nil, domain: :diet, parent: nil, name: "Fats",
|
||||||
|
description: "Total lipids, including phospholipids", primary: true
|
||||||
|
f1 = Quantity.create project: nil, domain: :diet, parent: f, name: "Fatty acids",
|
||||||
|
description: ""
|
||||||
|
f2 = Quantity.create project: nil, domain: :diet, parent: f1, name: "Saturated",
|
||||||
|
description: "Fatty acids without double bond"
|
||||||
|
f3 = Quantity.create project: nil, domain: :diet, parent: f1, name: "Unsaturated",
|
||||||
|
description: ""
|
||||||
|
f4 = Quantity.create project: nil, domain: :diet, parent: f3, name: "Monounsaturated",
|
||||||
|
description: "Fatty acids with one cis double bond"
|
||||||
|
f5 = Quantity.create project: nil, domain: :diet, parent: f3, name: "Polyunsaturated",
|
||||||
|
description: "Fatty acids with two or more cis, cis-methylene interrupted" \
|
||||||
|
" double bonds; PUFA"
|
||||||
|
f6 = Quantity.create project: nil, domain: :diet, parent: f3, name: "Trans",
|
||||||
|
description: "Fatty acids with at least one non-conjugated C-C double bond in the" \
|
||||||
|
" trans configuration"
|
||||||
|
f7 = Quantity.create project: nil, domain: :diet, parent: f5, name: "Omega-3 (n-3)",
|
||||||
|
description: ""
|
||||||
|
f8 = Quantity.create project: nil, domain: :diet, parent: f5, name: "Omega-6 (n-6)",
|
||||||
|
description: ""
|
||||||
|
f9 = Quantity.create project: nil, domain: :diet, parent: f7, name: "ALA 18:3(n-3)",
|
||||||
|
description: "alpha-Linolenic acid"
|
||||||
|
f10 = Quantity.create project: nil, domain: :diet, parent: f7, name: "EPA 20:5(n-3)",
|
||||||
|
description: "Eicosapentaenoic acid; also icosapentaenoic acid"
|
||||||
|
f11 = Quantity.create project: nil, domain: :diet, parent: f7, name: "DHA 22:6(n-3)",
|
||||||
|
description: "Docosahexaenoic acid"
|
||||||
|
|
||||||
|
c1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Carbohydrates",
|
||||||
|
description: "Total amount of carbohydrates", primary: true
|
||||||
|
c2 = Quantity.create project: nil, domain: :diet, parent: c1, name: "Digestible",
|
||||||
|
description: ""
|
||||||
|
c3 = Quantity.create project: nil, domain: :diet, parent: c2, name: "Sugars",
|
||||||
|
description: "Monosaccharides and disaccharides, excluding polyols"
|
||||||
|
c4 = Quantity.create project: nil, domain: :diet, parent: c3, name: "Monosaccharides",
|
||||||
|
description: ""
|
||||||
|
c5 = Quantity.create project: nil, domain: :diet, parent: c4, name: "Glucose",
|
||||||
|
description: ""
|
||||||
|
c6 = Quantity.create project: nil, domain: :diet, parent: c4, name: "Fructose",
|
||||||
|
description: ""
|
||||||
|
c7 = Quantity.create project: nil, domain: :diet, parent: c3, name: "Disaccharides",
|
||||||
|
description: ""
|
||||||
|
c8 = Quantity.create project: nil, domain: :diet, parent: c7, name: "Sucrose",
|
||||||
|
description: ""
|
||||||
|
c9 = Quantity.create project: nil, domain: :diet, parent: c7, name: "Lactose",
|
||||||
|
description: ""
|
||||||
|
c10 = Quantity.create project: nil, domain: :diet, parent: c2, name: "Polyols",
|
||||||
|
description: "Alcohols containing more than 2 hydroxyl groups"
|
||||||
|
c11 = Quantity.create project: nil, domain: :diet, parent: c2,
|
||||||
|
name: "Polysaccharides", description: ""
|
||||||
|
c12 = Quantity.create project: nil, domain: :diet, parent: c11, name: "Starch",
|
||||||
|
description: ""
|
||||||
|
c13 = Quantity.create project: nil, domain: :diet, parent: c1, name: "Indigestible",
|
||||||
|
description: ""
|
||||||
|
c14 = Quantity.create project: nil, domain: :diet, parent: c13, name: "Fibre",
|
||||||
|
description: "Carbohydrate polymers with 3 or more monomeric units, which are" \
|
||||||
|
" neither digested nor absorbed in the human small intestine"
|
||||||
|
|
||||||
|
m1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Minerals",
|
||||||
|
description: ""
|
||||||
|
m2 = Quantity.create project: nil, domain: :diet, parent: m1, name: "Salt",
|
||||||
|
description: "Sodium chloride"
|
||||||
|
|
||||||
|
v1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Vitamins",
|
||||||
|
description: ""
|
||||||
|
v2 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin A",
|
||||||
|
description: ""
|
||||||
|
v3 = Quantity.create project: nil, domain: :diet, parent: v2, name: "Retinol (A1)",
|
||||||
|
description: ""
|
||||||
|
v4 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Provitamin A",
|
||||||
|
description: ""
|
||||||
|
v5 = Quantity.create project: nil, domain: :diet, parent: v4, name: "beta-Carotene",
|
||||||
|
description: ""
|
||||||
|
v6 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin B",
|
||||||
|
description: ""
|
||||||
|
v7 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Thiamine (B1)",
|
||||||
|
description: ""
|
||||||
|
v8 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Riboflavin (B2)",
|
||||||
|
description: "Vitamin G"
|
||||||
|
v9 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Vitamin B3",
|
||||||
|
description: "Vitamin PP"
|
||||||
|
v10 = Quantity.create project: nil, domain: :diet, parent: v9, name: "Niacin",
|
||||||
|
description: "Nicotinic acid"
|
||||||
|
v11 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Vitamin B5",
|
||||||
|
description: "Pantothenic acid"
|
||||||
|
v12 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Vitamin B6",
|
||||||
|
description: ""
|
||||||
|
v13 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Biotin (B7)",
|
||||||
|
description: "Vitamin H, also coenzyme R"
|
||||||
|
v14 = Quantity.create project: nil, domain: :diet, parent: v6, name: "Folate",
|
||||||
|
description: "Includes: folic acid, folacin and vitamin B9"
|
||||||
|
v15 = Quantity.create project: nil, domain: :diet, parent: v14, name: "Vitamin B9",
|
||||||
|
description: ""
|
||||||
|
v16 = Quantity.create project: nil, domain: :diet, parent: v6,
|
||||||
|
name: "Cobalamin (B12)", description: ""
|
||||||
|
v17 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin C",
|
||||||
|
description: ""
|
||||||
|
v18 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin D",
|
||||||
|
description: "Calciferol"
|
||||||
|
v19 = Quantity.create project: nil, domain: :diet, parent: v18,
|
||||||
|
name: "Cholecalciferol (D3)", description: ""
|
||||||
|
v20 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin E",
|
||||||
|
description: ""
|
||||||
|
v21 = Quantity.create project: nil, domain: :diet, parent: v1, name: "Vitamin K",
|
||||||
|
description: ""
|
||||||
|
|
||||||
|
Source.create project: nil, name: "nutrition label",
|
||||||
|
description: "nutrition facts taken from package nutrition label"
|
||||||
|
end
|
||||||
|
dir.down do
|
||||||
|
Unit.where(project: nil).delete_all
|
||||||
|
Quantity.where(project: nil).delete_all
|
||||||
|
Source.where(project: nil).delete_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user