Add the book eidtions registry to manage book editions.

dev
KKlochko 4 months ago
parent ee72055f81
commit 43e2e24fee

@ -24,5 +24,7 @@ defmodule DecentralisedBookIndex.Metadata do
define :update_author_alias_registry, action: :update define :update_author_alias_registry, action: :update
define :destroy_author_alias_registry, action: :destroy define :destroy_author_alias_registry, action: :destroy
end end
resource DecentralisedBookIndex.Metadata.BookEditionsRegistry
end end
end end

@ -33,4 +33,8 @@ defmodule DecentralisedBookIndex.Metadata.Book do
timestamps() timestamps()
end end
relationships do
belongs_to :book_editions_registry, DecentralisedBookIndex.Metadata.BookEditionsRegistry
end
end end

@ -0,0 +1,31 @@
defmodule DecentralisedBookIndex.Metadata.BookEditionsRegistry do
use Ash.Resource,
otp_app: :decentralised_book_index,
domain: DecentralisedBookIndex.Metadata,
data_layer: AshPostgres.DataLayer
postgres do
table "book_editions_registries"
repo DecentralisedBookIndex.Repo
end
actions do
defaults [:read, :create, :update, :destroy]
read :by_id do
argument :id, :uuid, allow_nil?: false
get? true
filter expr(id == ^arg(:id))
end
end
attributes do
uuid_primary_key :id
timestamps()
end
relationships do
has_many :authors, DecentralisedBookIndex.Metadata.Book
end
end

@ -0,0 +1,58 @@
defmodule DecentralisedBookIndex.Repo.Migrations.CreateBookEditionsRegistyAndUpdateBookRelationships 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
alter table(:books) do
add :book_editions_registry_id, :uuid
end
create table(:book_editions_registries, primary_key: false) do
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
end
alter table(:books) do
modify :book_editions_registry_id,
references(:book_editions_registries,
column: :id,
name: "books_book_editions_registry_id_fkey",
type: :uuid,
prefix: "public"
)
end
alter table(:book_editions_registries) do
add :inserted_at, :utc_datetime_usec,
null: false,
default: fragment("(now() AT TIME ZONE 'utc')")
add :updated_at, :utc_datetime_usec,
null: false,
default: fragment("(now() AT TIME ZONE 'utc')")
end
end
def down do
alter table(:book_editions_registries) do
remove :updated_at
remove :inserted_at
end
drop constraint(:books, "books_book_editions_registry_id_fkey")
alter table(:books) do
modify :book_editions_registry_id, :uuid
end
drop table(:book_editions_registries)
alter table(:books) do
remove :book_editions_registry_id
end
end
end

@ -0,0 +1,49 @@
{
"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": "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"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "0404DB6E78482892C260ABA34469476A75E6807C808B78413AF8BF113EFD9027",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.DecentralisedBookIndex.Repo",
"schema": null,
"table": "book_editions_registries"
}

@ -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": "title",
"type": "text"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "isbn",
"type": "text"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "description",
"type": "text"
},
{
"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": "books_book_editions_registry_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "book_editions_registries"
},
"size": null,
"source": "book_editions_registry_id",
"type": "uuid"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": false,
"hash": "0EB9DD72D6C15F49DDAC97FC59931F963130A9A6002C1E08F7B567FDB1B886F0",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.DecentralisedBookIndex.Repo",
"schema": null,
"table": "books"
}
Loading…
Cancel
Save