summaryrefslogtreecommitdiff
path: root/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20200313203550_remove_orphaned_chat_names.rb')
-rw-r--r--db/post_migrate/20200313203550_remove_orphaned_chat_names.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb b/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb
new file mode 100644
index 00000000000..59cd2b31772
--- /dev/null
+++ b/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RemoveOrphanedChatNames < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ execute("DELETE FROM chat_names WHERE service_id NOT IN(SELECT id FROM services WHERE services.type = 'chat')")
+ end
+
+ def down
+ say 'Orphaned user chat names were removed as a part of this migration and are non-recoverable'
+ end
+end