zf

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

20211111175352_fill_vf_agent.exs (1977B)


      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_agent do
     19 use Ecto.Migration
     20 
     21 @mutex_check """
     22 (
     23 	type = 'per'
     24 	AND "user" IS NOT NULL
     25 	AND email IS NOT NULL
     26 	AND classified_as IS NULL
     27 )
     28 OR
     29 (
     30 	type = 'org'
     31 	AND "user" IS NULL
     32 	AND email IS NULL
     33 	AND ecdh_public_key IS NULL
     34 	AND eddsa_public_key IS NULL
     35 	AND ethereum_address IS NULL
     36 	AND reflow_public_key IS NULL
     37 	AND bitcoin_public_key IS NULL
     38 )
     39 """
     40 
     41 def change() do
     42 	alter table("vf_agent") do
     43 		add :type, :vf_agent_type, null: false
     44 
     45 		# common
     46 		add :name, :text, null: false
     47 		add :note, :text
     48 		add :primary_location_id, references("vf_spatial_thing")
     49 		timestamps()
     50 
     51 		# person
     52 		add :user, :text
     53 		add :email, :citext
     54 		add :ecdh_public_key, :text
     55 		add :eddsa_public_key, :text
     56 		add :ethereum_address, :text
     57 		add :reflow_public_key, :text
     58 		add :bitcoin_public_key, :text
     59 
     60 		# organization
     61 		add :classified_as, {:array, :text}
     62 	end
     63 
     64 	create index("vf_agent", :type)
     65 	create unique_index("vf_agent", :user, when: "user IS NOT NULL")
     66 	create unique_index("vf_agent", :email, when: "email IS NOT NULL")
     67 	create constraint("vf_agent", :type_mutex, check: @mutex_check)
     68 end
     69 end