zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

20211111114050_fill_vf_recipe_flow.exs (2427B)


      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.Fill_vf_recipe_flow do
     19 use Ecto.Migration
     20 
     21 @resqty_check """
     22 (resource_quantity_has_unit_id IS NOT NULL AND resource_quantity_has_numerical_value IS NOT NULL)
     23 OR
     24 (resource_quantity_has_unit_id IS NULL AND resource_quantity_has_numerical_value IS NULL)
     25 """
     26 @effqty_check """
     27 (effort_quantity_has_unit_id IS NOT NULL AND effort_quantity_has_numerical_value IS NOT NULL)
     28 OR
     29 (effort_quantity_has_unit_id IS NULL AND effort_quantity_has_numerical_value IS NULL)
     30 """
     31 @mutex_check """
     32 (resource_quantity_has_unit_id IS NOT NULL AND resource_quantity_has_numerical_value IS NOT NULL)
     33 OR
     34 (effort_quantity_has_unit_id IS NOT NULL AND effort_quantity_has_numerical_value IS NOT NULL)
     35 """
     36 
     37 def change() do
     38 	alter table("vf_recipe_flow") do
     39 		add :note, :text
     40 		add :action_id, :vf_action_id, null: false
     41 		add :recipe_input_of_id, references("vf_recipe_process")
     42 		add :recipe_output_of_id, references("vf_recipe_process")
     43 		add :recipe_clause_of_id, references("vf_recipe_exchange")
     44 		add :recipe_flow_resource_id, references("vf_recipe_resource"), null: false
     45 		add :resource_quantity_has_unit_id, references("vf_unit")
     46 		add :resource_quantity_has_numerical_value, :decimal
     47 		add :effort_quantity_has_unit_id, references("vf_unit")
     48 		add :effort_quantity_has_numerical_value, :decimal
     49 		timestamps()
     50 	end
     51 
     52 	create constraint("vf_recipe_flow", :resource_quantity_check, check: @resqty_check)
     53 	create constraint("vf_recipe_flow", :effort_quantity_check, check: @effqty_check)
     54 	create constraint("vf_recipe_flow", :measure_mutex, check: @mutex_check)
     55 end
     56 end