Add the book eidtions registry to manage book editions.
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
defmodule DecentralisedBookIndex.Repo.Migrations.CreateBookEditionsRegistyAndUpdateBookRelationships 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(:books) do
|
||||
add :book_editions_registry_id, :uuid
|
||||
end
|
||||
|
||||
create table(:book_editions_registries, primary_key: false) do
|
||||
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
|
||||
end
|
||||
|
||||
alter table(:books) do
|
||||
modify :book_editions_registry_id,
|
||||
references(:book_editions_registries,
|
||||
column: :id,
|
||||
name: "books_book_editions_registry_id_fkey",
|
||||
type: :uuid,
|
||||
prefix: "public"
|
||||
)
|
||||
end
|
||||
|
||||
alter table(:book_editions_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(:book_editions_registries) do
|
||||
remove :updated_at
|
||||
remove :inserted_at
|
||||
end
|
||||
|
||||
drop constraint(:books, "books_book_editions_registry_id_fkey")
|
||||
|
||||
alter table(:books) do
|
||||
modify :book_editions_registry_id, :uuid
|
||||
end
|
||||
|
||||
drop table(:book_editions_registries)
|
||||
|
||||
alter table(:books) do
|
||||
remove :book_editions_registry_id
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user