ash_hq/priv/repo/migrations/20230401210721_migrate_resources50.exs

96 lines
2.3 KiB
Elixir
Raw Normal View History

defmodule AshHq.Repo.Migrations.MigrateResources50 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(:users) do
2023-04-02 17:27:29 +12:00
add(:ashley_access, :boolean, default: false)
end
create table(:questions, primary_key: false) do
2023-04-02 17:27:29 +12:00
add(:id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true)
add(:question, :text, null: false)
add(:answer, :text, null: false)
add(:answer_html, :text, null: false)
add(:success, :boolean, null: false)
add(:inserted_at, :utc_datetime_usec, null: false, default: fragment("now()"))
add(:updated_at, :utc_datetime_usec, null: false, default: fragment("now()"))
add(
:user_id,
references(:users,
column: :id,
name: "questions_user_id_fkey",
type: :uuid,
prefix: "public"
),
null: false
)
add(:conversation_id, :uuid, null: false)
end
create table(:conversations, primary_key: false) do
2023-04-02 17:27:29 +12:00
add(:id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true)
end
alter table(:questions) do
2023-04-02 17:27:29 +12:00
modify(
:conversation_id,
references(:conversations,
column: :id,
prefix: "public",
name: "questions_conversation_id_fkey",
type: :uuid,
on_delete: :delete_all
)
)
end
alter table(:conversations) do
2023-04-02 17:27:29 +12:00
add(:name, :text)
add(
:user_id,
references(:users,
column: :id,
name: "conversations_user_id_fkey",
type: :uuid,
prefix: "public"
),
null: false
)
end
end
def down do
2023-04-02 17:27:29 +12:00
drop(constraint(:conversations, "conversations_user_id_fkey"))
alter table(:conversations) do
2023-04-02 17:27:29 +12:00
remove(:user_id)
remove(:name)
end
2023-04-02 17:27:29 +12:00
drop(constraint(:questions, "questions_conversation_id_fkey"))
alter table(:questions) do
2023-04-02 17:27:29 +12:00
modify(:conversation_id, :uuid)
end
2023-04-02 17:27:29 +12:00
drop(table(:conversations))
2023-04-02 17:27:29 +12:00
drop(constraint(:questions, "questions_user_id_fkey"))
2023-04-02 17:27:29 +12:00
drop(table(:questions))
alter table(:users) do
2023-04-02 17:27:29 +12:00
remove(:ashley_access)
end
end
2023-04-02 17:27:29 +12:00
end