From 69c24b8b25eed48da2fba27e76a852f9a0a883ec Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 8 Nov 2018 17:57:10 +0100 Subject: [PATCH] Fix comments table references Signed-off-by: Thomas Citharel --- ...20181108165151_fix_comments_references.exs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 priv/repo/migrations/20181108165151_fix_comments_references.exs diff --git a/priv/repo/migrations/20181108165151_fix_comments_references.exs b/priv/repo/migrations/20181108165151_fix_comments_references.exs new file mode 100644 index 000000000..128c2865c --- /dev/null +++ b/priv/repo/migrations/20181108165151_fix_comments_references.exs @@ -0,0 +1,26 @@ +defmodule Mobilizon.Repo.Migrations.FixCommentsReferences do + @moduledoc """ + For some reason these fields references were all wrong. + """ + use Ecto.Migration + + def up do + drop constraint(:comments, "comments_in_reply_to_comment_id_fkey") + drop constraint(:comments, "comments_origin_comment_id_fkey") + + alter table(:comments) do + modify :in_reply_to_comment_id, references(:comments, on_delete: :nothing) + modify :origin_comment_id, references(:comments, on_delete: :nothing) + end + end + + def down do + drop constraint(:comments, "comments_in_reply_to_comment_id_fkey") + drop constraint(:comments, "comments_origin_comment_id_fkey") + + alter table(:comments) do + modify :in_reply_to_comment_id, references(:categories, on_delete: :nothing) + modify :origin_comment_id, references(:addresses, on_delete: :delete_all) + end + end +end