Ran the needful migrations for replacing channels with sources
This commit is contained in:
parent
9e17b4aa6a
commit
d336f6f46c
2 changed files with 65 additions and 0 deletions
|
|
@ -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
|
||||||
21
priv/repo/migrations/20240202043042_drop_channels_table.exs
Normal file
21
priv/repo/migrations/20240202043042_drop_channels_table.exs
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in a new issue