Add the author alias registry to manage alias relationship.

Add datalayer and migrations.
This commit is contained in:
2025-03-06 21:49:45 +02:00
parent 2b6702c96d
commit 91f0fcd021
5 changed files with 253 additions and 1 deletions
@@ -0,0 +1,58 @@
defmodule DecentralisedBookIndex.Repo.Migrations.CreateAuthorAliasRegistyAndUpdateAuthorRelationships 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_alias_registry_id, :uuid
end
create table(:author_alias_registries, primary_key: false) do
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
end
alter table(:authors) do
modify :author_alias_registry_id,
references(:author_alias_registries,
column: :id,
name: "authors_author_alias_registry_id_fkey",
type: :uuid,
prefix: "public"
)
end
alter table(:author_alias_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(:author_alias_registries) do
remove :updated_at
remove :inserted_at
end
drop constraint(:authors, "authors_author_alias_registry_id_fkey")
alter table(:authors) do
modify :author_alias_registry_id, :uuid
end
drop table(:author_alias_registries)
alter table(:authors) do
remove :author_alias_registry_id
end
end
end