diff --git a/lib/membership/property.ex b/lib/membership/property.ex index 14ab4f1..433fc63 100644 --- a/lib/membership/property.ex +++ b/lib/membership/property.ex @@ -4,7 +4,7 @@ defmodule Mv.Membership.Property do data_layer: AshPostgres.DataLayer postgres do - table "attribute" + table "properties" repo Mv.Repo end diff --git a/lib/mv_web/member_live/form_component.ex b/lib/mv_web/member_live/form_component.ex index b6830d6..b91d3c0 100644 --- a/lib/mv_web/member_live/form_component.ex +++ b/lib/mv_web/member_live/form_component.ex @@ -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 = diff --git a/priv/repo/migrations/20250507171618_initial_migration.exs b/priv/repo/migrations/20250514151922_initial_migration.exs similarity index 58% rename from priv/repo/migrations/20250507171618_initial_migration.exs rename to priv/repo/migrations/20250514151922_initial_migration.exs index c3698d7..64915c2 100644 --- a/priv/repo/migrations/20250507171618_initial_migration.exs +++ b/priv/repo/migrations/20250514151922_initial_migration.exs @@ -19,41 +19,50 @@ 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 + alter table(:properties) do + modify :member_id, + references(:members, + column: :id, + name: "properties_member_id_fkey", + type: :uuid, + prefix: "public" + ) - add :member_id, - references(:members, - column: :id, - name: "attribute_member_id_fkey", - type: :uuid, - prefix: "public" - ) - - add :property_type_id, - references(:property_types, - column: :id, - name: "attribute_property_type_id_fkey", - type: :uuid, - prefix: "public" - ) + modify :property_type_id, + references(:property_types, + column: :id, + name: "properties_property_type_id_fkey", + type: :uuid, + prefix: "public" + ) end 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" ) diff --git a/priv/resource_snapshots/repo/members/20250507171618.json b/priv/resource_snapshots/repo/members/20250514151922.json similarity index 100% rename from priv/resource_snapshots/repo/members/20250507171618.json rename to priv/resource_snapshots/repo/members/20250514151922.json diff --git a/priv/resource_snapshots/repo/attribute/20250507171618.json b/priv/resource_snapshots/repo/properties/20250514151922.json similarity index 91% rename from priv/resource_snapshots/repo/attribute/20250507171618.json rename to priv/resource_snapshots/repo/properties/20250514151922.json index 1f772ae..0707bcf 100644 --- a/priv/resource_snapshots/repo/attribute/20250507171618.json +++ b/priv/resource_snapshots/repo/properties/20250514151922.json @@ -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" } \ No newline at end of file diff --git a/priv/resource_snapshots/repo/property_types/20250507171618.json b/priv/resource_snapshots/repo/property_types/20250514151922.json similarity index 100% rename from priv/resource_snapshots/repo/property_types/20250507171618.json rename to priv/resource_snapshots/repo/property_types/20250514151922.json