diff --git a/lib/decentralised_book_index/metadata/author.ex b/lib/decentralised_book_index/metadata/author.ex index e1509d5..f73fb77 100644 --- a/lib/decentralised_book_index/metadata/author.ex +++ b/lib/decentralised_book_index/metadata/author.ex @@ -115,8 +115,6 @@ defmodule DecentralisedBookIndex.Metadata.Author do attribute_writable? true end - belongs_to :author_role, Metadata.AuthorRole do - attribute_writable? true - end + has_many :author_role, Metadata.AuthorRole end end diff --git a/lib/decentralised_book_index/metadata/author_role.ex b/lib/decentralised_book_index/metadata/author_role.ex index 670e7e2..a190c9c 100644 --- a/lib/decentralised_book_index/metadata/author_role.ex +++ b/lib/decentralised_book_index/metadata/author_role.ex @@ -42,8 +42,8 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do allow_nil? true end - has_one :author, Metadata.Author do - allow_nil? false + belongs_to :author, Metadata.Author do + allow_nil? true end end end diff --git a/priv/repo/migrations/20250311182445_update_author_and_author_role_relationship.exs b/priv/repo/migrations/20250311182445_update_author_and_author_role_relationship.exs new file mode 100644 index 0000000..12d0c2b --- /dev/null +++ b/priv/repo/migrations/20250311182445_update_author_and_author_role_relationship.exs @@ -0,0 +1,43 @@ +defmodule DecentralisedBookIndex.Repo.Migrations.UpdateAuthorAndAuthorRoleRelationship 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(:authors) do + remove :author_role_id + end + + alter table(:author_role) do + add :author_id, + references(:authors, + column: :id, + name: "author_role_author_id_fkey", + type: :uuid, + prefix: "public" + ) + end + end + + def down do + drop constraint(:author_role, "author_role_author_id_fkey") + + alter table(:author_role) do + remove :author_id + end + + alter table(:authors) do + add :author_role_id, + references(:author_role, + column: :id, + name: "authors_author_role_id_fkey", + type: :uuid, + prefix: "public" + ) + end + end +end diff --git a/priv/resource_snapshots/repo/author_role/20250311182445.json b/priv/resource_snapshots/repo/author_role/20250311182445.json new file mode 100644 index 0000000..98c52b8 --- /dev/null +++ b/priv/resource_snapshots/repo/author_role/20250311182445.json @@ -0,0 +1,127 @@ +{ + "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_book_id_fkey", + "on_delete": null, + "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": "386FF5C297DF741B57842BF4690249CB624EFDE6F8B08B27A6E17071A44C8ABC", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "author_role" +} \ No newline at end of file diff --git a/priv/resource_snapshots/repo/authors/20250311182445.json b/priv/resource_snapshots/repo/authors/20250311182445.json new file mode 100644 index 0000000..7ceeb51 --- /dev/null +++ b/priv/resource_snapshots/repo/authors/20250311182445.json @@ -0,0 +1,98 @@ +{ + "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" + }, + { + "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": "authors_author_alias_registry_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "author_alias_registries" + }, + "size": null, + "source": "author_alias_registry_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true, + "hash": "490E9E7EB08795DE4BD8A1B1A01EAF8B0CCD813B9F659BD56658CA9B069C140F", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "authors" +} \ No newline at end of file