diff --git a/lib/decentralised_book_index/books/book.ex b/lib/decentralised_book_index/books/book.ex index 644ade4..31169a4 100644 --- a/lib/decentralised_book_index/books/book.ex +++ b/lib/decentralised_book_index/books/book.ex @@ -1,7 +1,13 @@ defmodule DecentralisedBookIndex.Books.Book do use Ash.Resource, otp_app: :decentralised_book_index, - domain: DecentralisedBookIndex.Books + domain: DecentralisedBookIndex.Books, + data_layer: AshPostgres.DataLayer + + postgres do + table "books" + repo DecentralisedBookIndex.Repo + end actions do defaults [:read] diff --git a/priv/repo/migrations/20250304195635_create_books.exs b/priv/repo/migrations/20250304195635_create_books.exs new file mode 100644 index 0000000..a23fe71 --- /dev/null +++ b/priv/repo/migrations/20250304195635_create_books.exs @@ -0,0 +1,30 @@ +defmodule DecentralisedBookIndex.Repo.Migrations.CreateBooks 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 + create table(:books, primary_key: false) do + add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true + add :title, :text, null: false + add :isbn, :text, null: false + add :description, :text, null: false + + 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 + drop table(:books) + end +end diff --git a/priv/resource_snapshots/repo/books/20250304195635.json b/priv/resource_snapshots/repo/books/20250304195635.json new file mode 100644 index 0000000..e9be2a7 --- /dev/null +++ b/priv/resource_snapshots/repo/books/20250304195635.json @@ -0,0 +1,79 @@ +{ + "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" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": false, + "hash": "C02C3C11E1ADB515594C9586C00852F7EC02649555AC07F9FCAFA27C403F0450", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "books" +} \ No newline at end of file