20220816154732_create_and_fill_zf_inst_vars.exs (2457B)
1 # Zenflows is designed to implement the Valueflows vocabulary, 2 # written and maintained by srfsh <info@dyne.org>. 3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>. 4 # 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU Affero General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU Affero General Public License for more details. 14 # 15 # You should have received a copy of the GNU Affero General Public License 16 # along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 defmodule Zenflows.DB.Repo.Migrations.Create_and_fill_zf_inst_vars do 19 use Ecto.Migration 20 21 alias Zenflows.InstVars 22 alias Zenflows.VF.{ResourceSpecification, Unit} 23 24 def up() do 25 create table("zf_inst_vars", primary_key: false) do 26 add :one_row, :boolean, default: true, primary_key: true 27 add :unit_one_id, references("vf_unit"), null: false 28 add :spec_currency_id, references("vf_resource_specification"), null: false 29 add :spec_project_design_id, references("vf_resource_specification"), null: false 30 add :spec_project_service_id, references("vf_resource_specification"), null: false 31 add :spec_project_product_id, references("vf_resource_specification"), null: false 32 end 33 34 create constraint("zf_inst_vars", :one_row, check: "one_row") 35 36 flush() 37 38 execute(fn -> 39 r = repo() 40 unit_one = Unit.Domain.create!(r, %{label: "one", symbol: "#"}) 41 spec_currency = ResourceSpecification.Domain.create!(r, %{name: "currency", default_unit_of_resource_id: unit_one.id}) 42 spec_design = ResourceSpecification.Domain.create!(r, %{name: "Design", default_unit_of_resource_id: unit_one.id}) 43 spec_service = ResourceSpecification.Domain.create!(r, %{name: "Service", default_unit_of_resource_id: unit_one.id}) 44 spec_product = ResourceSpecification.Domain.create!(r, %{name: "Product", default_unit_of_resource_id: unit_one.id}) 45 46 r.insert!(%InstVars{ 47 unit_one_id: unit_one.id, 48 spec_currency_id: spec_currency.id, 49 spec_project_design_id: spec_design.id, 50 spec_project_service_id: spec_service.id, 51 spec_project_product_id: spec_product.id, 52 }) 53 end) 54 end 55 56 def down() do 57 drop table("zf_inst_vars") 58 end 59 end