fix member deletion: property delete on cascade
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Moritz 2025-06-17 15:28:52 +02:00
parent 68c7b6fcae
commit 6b770a98ef
Signed by: moritz
GPG key ID: 1020A035E5DD0824
4 changed files with 154 additions and 2 deletions

View file

@ -9,7 +9,7 @@ defmodule Mv.Membership.Member do
end end
actions do actions do
defaults [:read, :destroy] defaults [:read]
create :create_member do create :create_member do
primary? true primary? true
@ -34,6 +34,11 @@ defmodule Mv.Membership.Member do
change manage_relationship(:properties, type: :create) change manage_relationship(:properties, type: :create)
end end
destroy :destroy do
primary? true
change Ash.Resource.Change.Builtins.cascade_destroy(:properties)
end
update :update_member do update :update_member do
primary? true primary? true
require_atomic? false require_atomic? false
@ -211,6 +216,6 @@ defmodule Mv.Membership.Member do
end end
relationships do relationships do
has_many :properties, Mv.Membership.Property has_many :properties, Mv.Membership.Property, destination_attribute: :member_id
end end
end end

View file

@ -6,6 +6,10 @@ defmodule Mv.Membership.Property do
postgres do postgres do
table "properties" table "properties"
repo Mv.Repo repo Mv.Repo
references do
reference :member, on_delete: :delete
end
end end
actions do actions do

View file

@ -0,0 +1,38 @@
defmodule Mv.Repo.Migrations.MemberDelete do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_postgres.generate_migrations`
"""
use Ecto.Migration
def up do
drop constraint(:properties, "properties_member_id_fkey")
alter table(:properties) do
modify :member_id,
references(:members,
column: :id,
name: "properties_member_id_fkey",
type: :uuid,
prefix: "public",
on_delete: :delete_all
)
end
end
def down do
drop constraint(:properties, "properties_member_id_fkey")
alter table(:properties) do
modify :member_id,
references(:members,
column: :id,
name: "properties_member_id_fkey",
type: :uuid,
prefix: "public"
)
end
end
end

View file

@ -0,0 +1,105 @@
{
"attributes": [
{
"allow_nil?": false,
"default": "fragment(\"gen_random_uuid()\")",
"generated?": false,
"precision": null,
"primary_key?": true,
"references": null,
"scale": null,
"size": null,
"source": "id",
"type": "uuid"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"precision": null,
"primary_key?": false,
"references": null,
"scale": null,
"size": null,
"source": "value",
"type": "map"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"precision": null,
"primary_key?": false,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": false,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "properties_member_id_fkey",
"on_delete": "delete",
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "members"
},
"scale": null,
"size": null,
"source": "member_id",
"type": "uuid"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"precision": null,
"primary_key?": false,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": false,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "properties_property_type_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "property_types"
},
"scale": null,
"size": null,
"source": "property_type_id",
"type": "uuid"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "4F17BE0106435A1D75D46A3ABDE6A3DA20FC9B1C43D101B6C310009279DD7CBA",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.Mv.Repo",
"schema": null,
"table": "properties"
}