Add AuthorRole to manage relationship between Author and Book.

This commit is contained in:
2025-03-09 22:03:51 +02:00
parent d4c73cb647
commit 9cdedf0c7c
9 changed files with 494 additions and 4 deletions
@@ -0,0 +1,75 @@
defmodule DecentralisedBookIndex.Repo.Migrations.CreateAuthorRoleAndUpdateRelationships 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
add :author_role_id, :uuid
end
create table(:author_role, primary_key: false) do
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
end
alter table(:authors) do
modify :author_role_id,
references(:author_role,
column: :id,
name: "authors_author_role_id_fkey",
type: :uuid,
prefix: "public"
)
end
alter table(:author_role) do
add :role, :text, null: false
add :order, :bigint, 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')")
add :book_id,
references(:books,
column: :id,
name: "author_role_book_id_fkey",
type: :uuid,
prefix: "public"
),
null: false
end
end
def down do
drop constraint(:author_role, "author_role_book_id_fkey")
alter table(:author_role) do
remove :book_id
remove :updated_at
remove :inserted_at
remove :order
remove :role
end
drop constraint(:authors, "authors_author_role_id_fkey")
alter table(:authors) do
modify :author_role_id, :uuid
end
drop table(:author_role)
alter table(:authors) do
remove :author_role_id
end
end
end
@@ -0,0 +1,23 @@
defmodule DecentralisedBookIndex.Repo.Migrations.UpdateAuthorRoleToAllowEmptyRoleAndBookRelationship 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(:author_role) do
modify :book_id, :uuid, null: true
modify :role, :text, null: true
end
end
def down do
alter table(:author_role) do
modify :role, :text, null: false
modify :book_id, :uuid, null: false
end
end
end