2023-01-22 19:36:48 +13:00
|
|
|
defmodule AshHq.Repo.Migrations.MigrateResources43 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
|
|
|
|
create table(:discord_threads, primary_key: false) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:id, :bigint, null: false, primary_key: true)
|
|
|
|
add(:type, :bigint)
|
|
|
|
add(:name, :text, null: false)
|
|
|
|
add(:author, :text, null: false)
|
|
|
|
add(:create_timestamp, :utc_datetime, null: false)
|
|
|
|
add(:channel_id, :bigint, null: false)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
create table(:discord_thread_tags, primary_key: false) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(
|
|
|
|
:thread_id,
|
|
|
|
references(:discord_threads,
|
|
|
|
column: :id,
|
|
|
|
name: "discord_thread_tags_thread_id_fkey",
|
|
|
|
type: :bigint,
|
|
|
|
prefix: "public"
|
|
|
|
),
|
|
|
|
primary_key: true,
|
|
|
|
null: false
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:tag_id, :bigint, null: false, primary_key: true)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
create table(:discord_tags, primary_key: false) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:id, :bigint, null: false, primary_key: true)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
alter table(:discord_thread_tags) do
|
2023-01-22 20:51:02 +13:00
|
|
|
modify(
|
|
|
|
:tag_id,
|
|
|
|
references(:discord_tags,
|
|
|
|
column: :id,
|
|
|
|
prefix: "public",
|
|
|
|
name: "discord_thread_tags_tag_id_fkey",
|
|
|
|
type: :bigint
|
|
|
|
)
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
alter table(:discord_tags) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:name, :citext, null: false)
|
|
|
|
add(:channel_id, :bigint)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
create table(:discord_reactions, primary_key: false) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true)
|
|
|
|
add(:count, :bigint, null: false)
|
|
|
|
add(:emoji, :text, null: false)
|
|
|
|
add(:message_id, :bigint, null: false)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
create table(:discord_messages, primary_key: false) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:id, :bigint, null: false, primary_key: true)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
alter table(:discord_reactions) do
|
2023-01-22 20:51:02 +13:00
|
|
|
modify(
|
|
|
|
:message_id,
|
|
|
|
references(:discord_messages,
|
|
|
|
column: :id,
|
|
|
|
prefix: "public",
|
|
|
|
name: "discord_reactions_message_id_fkey",
|
|
|
|
type: :bigint
|
|
|
|
)
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
create unique_index(:discord_reactions, [:emoji, :message_id],
|
|
|
|
name: "discord_reactions_unique_message_emoji_index"
|
|
|
|
)
|
|
|
|
|
|
|
|
alter table(:discord_messages) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:author, :text, null: false)
|
|
|
|
add(:content, :text)
|
|
|
|
add(:content_html, :text)
|
|
|
|
add(:timestamp, :utc_datetime, null: false)
|
|
|
|
|
|
|
|
add(
|
|
|
|
:thread_id,
|
|
|
|
references(:discord_threads,
|
|
|
|
column: :id,
|
|
|
|
name: "discord_messages_thread_id_fkey",
|
|
|
|
type: :bigint,
|
|
|
|
prefix: "public"
|
|
|
|
),
|
|
|
|
null: false
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
create table(:discord_channels, primary_key: false) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:id, :bigint, null: false, primary_key: true)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
alter table(:discord_threads) do
|
2023-01-22 20:51:02 +13:00
|
|
|
modify(
|
|
|
|
:channel_id,
|
|
|
|
references(:discord_channels,
|
|
|
|
column: :id,
|
|
|
|
prefix: "public",
|
|
|
|
name: "discord_threads_channel_id_fkey",
|
|
|
|
type: :bigint
|
|
|
|
)
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
alter table(:discord_tags) do
|
2023-01-22 20:51:02 +13:00
|
|
|
modify(
|
|
|
|
:channel_id,
|
|
|
|
references(:discord_channels,
|
|
|
|
column: :id,
|
|
|
|
prefix: "public",
|
|
|
|
name: "discord_tags_channel_id_fkey",
|
|
|
|
type: :bigint
|
|
|
|
)
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
create unique_index(:discord_tags, [:name, :channel_id],
|
|
|
|
name: "discord_tags_unique_name_per_channel_index"
|
|
|
|
)
|
|
|
|
|
|
|
|
alter table(:discord_channels) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:name, :text, null: false)
|
|
|
|
add(:order, :bigint, null: false)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
create table(:discord_attachments, primary_key: false) do
|
2023-01-22 20:51:02 +13:00
|
|
|
add(:id, :bigint, null: false, primary_key: true)
|
|
|
|
add(:filename, :text)
|
|
|
|
add(:size, :bigint)
|
|
|
|
add(:url, :text)
|
|
|
|
add(:proxy_url, :text)
|
|
|
|
add(:height, :bigint)
|
|
|
|
add(:width, :bigint)
|
|
|
|
|
|
|
|
add(
|
|
|
|
:message_id,
|
|
|
|
references(:discord_messages,
|
|
|
|
column: :id,
|
|
|
|
name: "discord_attachments_message_id_fkey",
|
|
|
|
type: :bigint,
|
|
|
|
prefix: "public"
|
|
|
|
),
|
|
|
|
null: false
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down do
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(constraint(:discord_attachments, "discord_attachments_message_id_fkey"))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(table(:discord_attachments))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
|
|
|
alter table(:discord_channels) do
|
2023-01-22 20:51:02 +13:00
|
|
|
remove(:order)
|
|
|
|
remove(:name)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop_if_exists(
|
|
|
|
unique_index(:discord_tags, [:name, :channel_id],
|
|
|
|
name: "discord_tags_unique_name_per_channel_index"
|
|
|
|
)
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(constraint(:discord_tags, "discord_tags_channel_id_fkey"))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
|
|
|
alter table(:discord_tags) do
|
2023-01-22 20:51:02 +13:00
|
|
|
modify(:channel_id, :bigint)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(constraint(:discord_threads, "discord_threads_channel_id_fkey"))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
|
|
|
alter table(:discord_threads) do
|
2023-01-22 20:51:02 +13:00
|
|
|
modify(:channel_id, :bigint)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(table(:discord_channels))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(constraint(:discord_messages, "discord_messages_thread_id_fkey"))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
|
|
|
alter table(:discord_messages) do
|
2023-01-22 20:51:02 +13:00
|
|
|
remove(:thread_id)
|
|
|
|
remove(:timestamp)
|
|
|
|
remove(:content_html)
|
|
|
|
remove(:content)
|
|
|
|
remove(:author)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop_if_exists(
|
|
|
|
unique_index(:discord_reactions, [:emoji, :message_id],
|
|
|
|
name: "discord_reactions_unique_message_emoji_index"
|
|
|
|
)
|
|
|
|
)
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(constraint(:discord_reactions, "discord_reactions_message_id_fkey"))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
|
|
|
alter table(:discord_reactions) do
|
2023-01-22 20:51:02 +13:00
|
|
|
modify(:message_id, :bigint)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(table(:discord_messages))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(table(:discord_reactions))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
|
|
|
alter table(:discord_tags) do
|
2023-01-22 20:51:02 +13:00
|
|
|
remove(:channel_id)
|
|
|
|
remove(:name)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(constraint(:discord_thread_tags, "discord_thread_tags_tag_id_fkey"))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
|
|
|
alter table(:discord_thread_tags) do
|
2023-01-22 20:51:02 +13:00
|
|
|
modify(:tag_id, :bigint)
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(table(:discord_tags))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(constraint(:discord_thread_tags, "discord_thread_tags_thread_id_fkey"))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(table(:discord_thread_tags))
|
2023-01-22 19:36:48 +13:00
|
|
|
|
2023-01-22 20:51:02 +13:00
|
|
|
drop(table(:discord_threads))
|
2023-01-22 19:36:48 +13:00
|
|
|
end
|
2023-01-22 20:51:02 +13:00
|
|
|
end
|