From d336f6f46c59f155c1cb7b6fe43152425b60b044 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Thu, 1 Feb 2024 20:34:51 -0800 Subject: [PATCH] Ran the needful migrations for replacing channels with sources --- ...0724_rename_channel_and_related_fields.exs | 44 +++++++++++++++++++ .../20240202043042_drop_channels_table.exs | 21 +++++++++ 2 files changed, 65 insertions(+) create mode 100644 priv/repo/migrations/20240202040724_rename_channel_and_related_fields.exs create mode 100644 priv/repo/migrations/20240202043042_drop_channels_table.exs diff --git a/priv/repo/migrations/20240202040724_rename_channel_and_related_fields.exs b/priv/repo/migrations/20240202040724_rename_channel_and_related_fields.exs new file mode 100644 index 0000000..489b7d0 --- /dev/null +++ b/priv/repo/migrations/20240202040724_rename_channel_and_related_fields.exs @@ -0,0 +1,44 @@ +defmodule Pinchflat.Repo.Migrations.RenameChannelAndRelatedFields do + use Ecto.Migration + + def change do + # Creation + create table(:sources) do + add :name, :string, null: false + add :collection_type, :string, null: false + add :collection_id, :string, null: false + add :original_url, :string, null: false + add :media_profile_id, references(:media_profiles, on_delete: :restrict), null: false + + timestamps(type: :utc_datetime) + end + + alter table(:media_items) do + add :source_id, references(:sources, on_delete: :restrict), null: false + end + + alter table(:tasks) do + # `restrict` because we need to be sure to delete pending tasks when a source is deleted + add :source_id, references(:sources, on_delete: :restrict), null: true + end + + create index(:sources, [:media_profile_id]) + create unique_index(:sources, [:collection_id, :media_profile_id]) + + create index(:media_items, [:source_id]) + create unique_index(:media_items, [:media_id, :source_id]) + + # Deletion + drop index(:media_items, [:channel_id]) + drop unique_index(:media_items, [:media_id, :channel_id]) + + alter table(:tasks) do + # `restrict` because we need to be sure to delete pending tasks when a source is deleted + remove :channel_id, references(:channels, on_delete: :restrict), null: true + end + + alter table(:media_items) do + remove :channel_id, references(:channels, on_delete: :restrict), null: true + end + end +end diff --git a/priv/repo/migrations/20240202043042_drop_channels_table.exs b/priv/repo/migrations/20240202043042_drop_channels_table.exs new file mode 100644 index 0000000..6397b19 --- /dev/null +++ b/priv/repo/migrations/20240202043042_drop_channels_table.exs @@ -0,0 +1,21 @@ +defmodule Pinchflat.Repo.Migrations.DropChannelsTable do + use Ecto.Migration + + def up do + drop table(:channels) + end + + def down do + create table(:channels) do + add :name, :string, null: false + add :channel_id, :string, null: false + add :original_url, :string, null: false + add :media_profile_id, references(:media_profiles, on_delete: :restrict), null: false + + timestamps(type: :utc_datetime) + end + + create index(:channels, [:media_profile_id]) + create unique_index(:channels, [:channel_id, :media_profile_id]) + end +end