From f2b8e49a2f917e9bb6dacea78a9e6820b2850a4d Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 5 Mar 2025 22:09:23 +0200 Subject: [PATCH] Add the datalayer and migrations for Authors and DBIServers. --- .../metadata/author.ex | 8 ++- .../metadata/dbi_server.ex | 8 ++- .../20250305200752_create_authors.exs | 29 ++++++++ .../20250305200836_create_dbi_servers.exs | 29 ++++++++ .../repo/authors/20250305200752.json | 69 +++++++++++++++++++ .../repo/dbi_servers/20250305200836.json | 69 +++++++++++++++++++ 6 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20250305200752_create_authors.exs create mode 100644 priv/repo/migrations/20250305200836_create_dbi_servers.exs create mode 100644 priv/resource_snapshots/repo/authors/20250305200752.json create mode 100644 priv/resource_snapshots/repo/dbi_servers/20250305200836.json diff --git a/lib/decentralised_book_index/metadata/author.ex b/lib/decentralised_book_index/metadata/author.ex index bae5c1e..9b7cb8d 100644 --- a/lib/decentralised_book_index/metadata/author.ex +++ b/lib/decentralised_book_index/metadata/author.ex @@ -1,7 +1,13 @@ defmodule DecentralisedBookIndex.Metadata.Author do use Ash.Resource, otp_app: :decentralised_book_index, - domain: DecentralisedBookIndex.Metadata + domain: DecentralisedBookIndex.Metadata, + data_layer: AshPostgres.DataLayer + + postgres do + table "authors" + repo DecentralisedBookIndex.Repo + end actions do defaults [:read] diff --git a/lib/decentralised_book_index/metadata/dbi_server.ex b/lib/decentralised_book_index/metadata/dbi_server.ex index af0ded7..f877ff7 100644 --- a/lib/decentralised_book_index/metadata/dbi_server.ex +++ b/lib/decentralised_book_index/metadata/dbi_server.ex @@ -1,7 +1,13 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do use Ash.Resource, otp_app: :decentralised_book_index, - domain: DecentralisedBookIndex.Metadata + domain: DecentralisedBookIndex.Metadata, + data_layer: AshPostgres.DataLayer + + postgres do + table "dbi_servers" + repo DecentralisedBookIndex.Repo + end actions do defaults [:read] diff --git a/priv/repo/migrations/20250305200752_create_authors.exs b/priv/repo/migrations/20250305200752_create_authors.exs new file mode 100644 index 0000000..cf814f3 --- /dev/null +++ b/priv/repo/migrations/20250305200752_create_authors.exs @@ -0,0 +1,29 @@ +defmodule DecentralisedBookIndex.Repo.Migrations.CreateAuthors 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(:authors, primary_key: false) do + add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true + add :name, :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(:authors) + end +end diff --git a/priv/repo/migrations/20250305200836_create_dbi_servers.exs b/priv/repo/migrations/20250305200836_create_dbi_servers.exs new file mode 100644 index 0000000..f7c9966 --- /dev/null +++ b/priv/repo/migrations/20250305200836_create_dbi_servers.exs @@ -0,0 +1,29 @@ +defmodule DecentralisedBookIndex.Repo.Migrations.CreateDbiServers 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(:dbi_servers, primary_key: false) do + add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true + add :name, :text, null: false + add :url, :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(:dbi_servers) + end +end diff --git a/priv/resource_snapshots/repo/authors/20250305200752.json b/priv/resource_snapshots/repo/authors/20250305200752.json new file mode 100644 index 0000000..2ebe148 --- /dev/null +++ b/priv/resource_snapshots/repo/authors/20250305200752.json @@ -0,0 +1,69 @@ +{ + "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": "name", + "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": "12852520EEBCE612C1137B25060489E738B7A39DF4979C7329CA9AD24CA45F1C", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "authors" +} \ No newline at end of file diff --git a/priv/resource_snapshots/repo/dbi_servers/20250305200836.json b/priv/resource_snapshots/repo/dbi_servers/20250305200836.json new file mode 100644 index 0000000..3647660 --- /dev/null +++ b/priv/resource_snapshots/repo/dbi_servers/20250305200836.json @@ -0,0 +1,69 @@ +{ + "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": "name", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "url", + "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": "E39152B74297E9975B6B3DCC9112ECB75DB70D0C42A8BAA03B7DFCE152D3E2F5", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "dbi_servers" +} \ No newline at end of file