Update BookId to add the reference logic.

dev
KKlochko 3 months ago
parent ddd300625c
commit 709905a8e1

@ -9,16 +9,25 @@ defmodule DecentralisedBookIndex.Metadata.BookId do
postgres do postgres do
table "book_ids" table "book_ids"
repo DecentralisedBookIndex.Repo repo DecentralisedBookIndex.Repo
references do
reference :book, index?: true, on_delete: :delete
end
end end
actions do actions do
defaults [:read, :update, :destroy] defaults [:read, :destroy]
create :create do create :create do
primary? true primary? true
accept [:type, :bid, :order] accept [:type, :bid, :order]
end end
update :update do
primary? true
accept [:type, :bid, :order]
end
read :by_id do read :by_id do
argument :id, :uuid, allow_nil?: false argument :id, :uuid, allow_nil?: false
get? true get? true

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

@ -0,0 +1,108 @@
{
"attributes": [
{
"allow_nil?": false,
"default": "fragment(\"gen_random_uuid()\")",
"generated?": false,
"primary_key?": true,
"references": null,
"size": null,
"source": "id",
"type": "uuid"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "type",
"type": "text"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "bid",
"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?": true,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "book_ids_book_id_fkey",
"on_delete": "delete",
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "books"
},
"size": null,
"source": "book_id",
"type": "uuid"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "0C61931CA6A175418C2C2BAA9BA133BF7BC272119F73CFAF7E2F3A10FD0D4925",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.DecentralisedBookIndex.Repo",
"schema": null,
"table": "book_ids"
}
Loading…
Cancel
Save