Compare commits
2 commits
a468f3edbe
...
83aab8c47b
| Author | SHA1 | Date | |
|---|---|---|---|
| 83aab8c47b | |||
| 39d4223988 |
6 changed files with 40 additions and 29 deletions
|
|
@ -4,7 +4,7 @@ defmodule Mv.Membership.Property do
|
||||||
data_layer: AshPostgres.DataLayer
|
data_layer: AshPostgres.DataLayer
|
||||||
|
|
||||||
postgres do
|
postgres do
|
||||||
table "attribute"
|
table "properties"
|
||||||
repo Mv.Repo
|
repo Mv.Repo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,12 @@ defmodule MvWeb.MemberLive.FormComponent do
|
||||||
if member do
|
if member do
|
||||||
{:ok, member} = Ash.load(member, properties: [:property_type])
|
{:ok, member} = Ash.load(member, properties: [:property_type])
|
||||||
|
|
||||||
|
existing_properties =
|
||||||
|
member.properties
|
||||||
|
|> Enum.map(& &1.property_type_id)
|
||||||
|
|
||||||
is_missing_property = fn i ->
|
is_missing_property = fn i ->
|
||||||
not Enum.any?(member.properties, fn p ->
|
not Enum.member?(existing_properties, Map.get(i, "property_type_id"))
|
||||||
Map.get(i, "property_type_id") == p.property_type_id
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
form =
|
form =
|
||||||
|
|
|
||||||
|
|
@ -19,41 +19,50 @@ defmodule Mv.Repo.Migrations.InitialMigration do
|
||||||
|
|
||||||
create unique_index(:property_types, [:name], name: "property_types_unique_name_index")
|
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
|
create table(:members, primary_key: false) do
|
||||||
add :id, :uuid, null: false, default: fragment("uuid_generate_v7()"), primary_key: true
|
add :id, :uuid, null: false, default: fragment("uuid_generate_v7()"), primary_key: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create table(:attribute, primary_key: false) do
|
alter table(:properties) do
|
||||||
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
|
modify :member_id,
|
||||||
add :value, :text
|
references(:members,
|
||||||
|
column: :id,
|
||||||
|
name: "properties_member_id_fkey",
|
||||||
|
type: :uuid,
|
||||||
|
prefix: "public"
|
||||||
|
)
|
||||||
|
|
||||||
add :member_id,
|
modify :property_type_id,
|
||||||
references(:members,
|
references(:property_types,
|
||||||
column: :id,
|
column: :id,
|
||||||
name: "attribute_member_id_fkey",
|
name: "properties_property_type_id_fkey",
|
||||||
type: :uuid,
|
type: :uuid,
|
||||||
prefix: "public"
|
prefix: "public"
|
||||||
)
|
)
|
||||||
|
|
||||||
add :property_type_id,
|
|
||||||
references(:property_types,
|
|
||||||
column: :id,
|
|
||||||
name: "attribute_property_type_id_fkey",
|
|
||||||
type: :uuid,
|
|
||||||
prefix: "public"
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def down do
|
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(:members)
|
||||||
|
|
||||||
|
drop table(:properties)
|
||||||
|
|
||||||
drop_if_exists unique_index(:property_types, [:name],
|
drop_if_exists unique_index(:property_types, [:name],
|
||||||
name: "property_types_unique_name_index"
|
name: "property_types_unique_name_index"
|
||||||
)
|
)
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
"global": null,
|
"global": null,
|
||||||
"strategy": null
|
"strategy": null
|
||||||
},
|
},
|
||||||
"name": "attribute_member_id_fkey",
|
"name": "properties_member_id_fkey",
|
||||||
"on_delete": null,
|
"on_delete": null,
|
||||||
"on_update": null,
|
"on_update": null,
|
||||||
"primary_key?": true,
|
"primary_key?": true,
|
||||||
|
|
@ -67,7 +67,7 @@
|
||||||
"global": null,
|
"global": null,
|
||||||
"strategy": null
|
"strategy": null
|
||||||
},
|
},
|
||||||
"name": "attribute_property_type_id_fkey",
|
"name": "properties_property_type_id_fkey",
|
||||||
"on_delete": null,
|
"on_delete": null,
|
||||||
"on_update": null,
|
"on_update": null,
|
||||||
"primary_key?": true,
|
"primary_key?": true,
|
||||||
|
|
@ -84,7 +84,7 @@
|
||||||
"custom_indexes": [],
|
"custom_indexes": [],
|
||||||
"custom_statements": [],
|
"custom_statements": [],
|
||||||
"has_create_action": true,
|
"has_create_action": true,
|
||||||
"hash": "13CA0C29CA3D1F92B87271DF1B222CF8ADBB0D56A99575952A1432596F7B4A10",
|
"hash": "F2A42A3427E0428637F465E4F357A3BE21B33231F94CF77B4843084128F6BDA5",
|
||||||
"identities": [],
|
"identities": [],
|
||||||
"multitenancy": {
|
"multitenancy": {
|
||||||
"attribute": null,
|
"attribute": null,
|
||||||
|
|
@ -93,5 +93,5 @@
|
||||||
},
|
},
|
||||||
"repo": "Elixir.Mv.Repo",
|
"repo": "Elixir.Mv.Repo",
|
||||||
"schema": null,
|
"schema": null,
|
||||||
"table": "attribute"
|
"table": "properties"
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue