20220824130516_fill_zf_file.exs (1926B)
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.SQL.Repo.Migrations.Fill_zf_file do 19 use Ecto.Migration 20 21 @check """ 22 num_nonnulls( 23 recipe_resource_id, 24 economic_resource_id, 25 agent_id, 26 resource_specification_id, 27 intent_id 28 ) = 1 29 """ 30 31 def change() do 32 alter table("zf_file") do 33 add :hash, :text, null: false 34 add :name, :text, null: false 35 add :description, :text, null: false 36 add :mime_type, :text, null: false 37 add :extension, :text, null: false 38 add :size, :integer, null: false 39 add :signature, :text, null: false 40 add :width, :integer 41 add :height, :integer 42 add :bin, :text 43 timestamps() 44 45 add :recipe_resource_id, references("vf_recipe_resource", on_delete: :delete_all) 46 add :economic_resource_id, references("vf_economic_resource", on_delete: :delete_all) 47 add :agent_id, references("vf_agent", on_delete: :delete_all) 48 add :resource_specification_id, references("vf_resource_specification", on_delete: :delete_all) 49 add :intent_id, references("vf_intent", on_delete: :delete_all) 50 end 51 52 create unique_index("zf_file", :hash) 53 create constraint("zf_file", :mutex, check: @check) 54 end 55 end