Compare commits

..

2 commits

Author SHA1 Message Date
83aab8c47b
add liveview
Some checks failed
continuous-integration/drone/push Build is failing
2025-05-14 17:28:30 +02:00
39d4223988
member and properties 2025-05-14 17:28:26 +02:00
6 changed files with 40 additions and 29 deletions

View file

@ -4,7 +4,7 @@ defmodule Mv.Membership.Property do
data_layer: AshPostgres.DataLayer
postgres do
table "attribute"
table "properties"
repo Mv.Repo
end

View file

@ -87,10 +87,12 @@ defmodule MvWeb.MemberLive.FormComponent do
if member do
{:ok, member} = Ash.load(member, properties: [:property_type])
existing_properties =
member.properties
|> Enum.map(& &1.property_type_id)
is_missing_property = fn i ->
not Enum.any?(member.properties, fn p ->
Map.get(i, "property_type_id") == p.property_type_id
end)
not Enum.member?(existing_properties, Map.get(i, "property_type_id"))
end
form =

View file

@ -19,26 +19,30 @@ defmodule Mv.Repo.Migrations.InitialMigration do
create unique_index(:property_types, [:name], name: "property_types_unique_name_index")
create table(:properties, primary_key: false) do
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
add :value, :text
add :member_id, :uuid
add :property_type_id, :uuid
end
create table(:members, primary_key: false) do
add :id, :uuid, null: false, default: fragment("uuid_generate_v7()"), primary_key: true
end
create table(:attribute, primary_key: false) do
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
add :value, :text
add :member_id,
alter table(:properties) do
modify :member_id,
references(:members,
column: :id,
name: "attribute_member_id_fkey",
name: "properties_member_id_fkey",
type: :uuid,
prefix: "public"
)
add :property_type_id,
modify :property_type_id,
references(:property_types,
column: :id,
name: "attribute_property_type_id_fkey",
name: "properties_property_type_id_fkey",
type: :uuid,
prefix: "public"
)
@ -46,14 +50,19 @@ defmodule Mv.Repo.Migrations.InitialMigration do
end
def down do
drop constraint(:attribute, "attribute_member_id_fkey")
drop constraint(:properties, "properties_member_id_fkey")
drop constraint(:attribute, "attribute_property_type_id_fkey")
drop constraint(:properties, "properties_property_type_id_fkey")
drop table(:attribute)
alter table(:properties) do
modify :property_type_id, :uuid
modify :member_id, :uuid
end
drop table(:members)
drop table(:properties)
drop_if_exists unique_index(:property_types, [:name],
name: "property_types_unique_name_index"
)

View file

@ -38,7 +38,7 @@
"global": null,
"strategy": null
},
"name": "attribute_member_id_fkey",
"name": "properties_member_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
@ -67,7 +67,7 @@
"global": null,
"strategy": null
},
"name": "attribute_property_type_id_fkey",
"name": "properties_property_type_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
@ -84,7 +84,7 @@
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "13CA0C29CA3D1F92B87271DF1B222CF8ADBB0D56A99575952A1432596F7B4A10",
"hash": "F2A42A3427E0428637F465E4F357A3BE21B33231F94CF77B4843084128F6BDA5",
"identities": [],
"multitenancy": {
"attribute": null,
@ -93,5 +93,5 @@
},
"repo": "Elixir.Mv.Repo",
"schema": null,
"table": "attribute"
"table": "properties"
}