Update AuthorRole delete logic to cascade if no Book.

dev
KKlochko 3 months ago
parent d1a44a5457
commit 74570c81a1

@ -14,6 +14,10 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
postgres do
table "author_role"
repo DecentralisedBookIndex.Repo
references do
reference :book, index?: true, on_delete: :delete
end
end
actions do

@ -0,0 +1,42 @@
defmodule DecentralisedBookIndex.Repo.Migrations.UpdateAuthorRoleDeleteLogicToCascadeIfNoBook 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(:author_role, "author_role_book_id_fkey")
alter table(:author_role) do
modify :book_id,
references(:books,
column: :id,
name: "author_role_book_id_fkey",
type: :uuid,
prefix: "public",
on_delete: :delete_all
)
end
create index(:author_role, [:book_id])
end
def down do
drop_if_exists index(:author_role, [:book_id])
drop constraint(:author_role, "author_role_book_id_fkey")
alter table(:author_role) do
modify :book_id,
references(:books,
column: :id,
name: "author_role_book_id_fkey",
type: :uuid,
prefix: "public"
)
end
end
end

@ -0,0 +1,156 @@
{
"attributes": [
{
"allow_nil?": false,
"default": "fragment(\"gen_random_uuid()\")",
"generated?": false,
"primary_key?": true,
"references": null,
"size": null,
"source": "id",
"type": "uuid"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "role",
"type": "text"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "order",
"type": "bigint"
},
{
"allow_nil?": false,
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "inserted_at",
"type": "utc_datetime_usec"
},
{
"allow_nil?": false,
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "updated_at",
"type": "utc_datetime_usec"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"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": "author_role_dbi_server_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "dbi_servers"
},
"size": null,
"source": "dbi_server_id",
"type": "uuid"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": true,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "author_role_book_id_fkey",
"on_delete": "delete",
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "books"
},
"size": null,
"source": "book_id",
"type": "uuid"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"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": "author_role_author_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "authors"
},
"size": null,
"source": "author_id",
"type": "uuid"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "9E4F8AF2665BB1D2073A2FC4587C55DCB455E85298D4AADC87D221A8231771CD",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.DecentralisedBookIndex.Repo",
"schema": null,
"table": "author_role"
}
Loading…
Cancel
Save