FIX:Add migration to delete tracking state for staged users (#10083)

FIX:Add migration to delete tracking state for staged users (#10083)

diff --git a/db/migrate/20200618175923_delete_tracking_state_for_staged_users.rb b/db/migrate/20200618175923_delete_tracking_state_for_staged_users.rb
new file mode 100644
index 0000000..9885b56
--- /dev/null
+++ b/db/migrate/20200618175923_delete_tracking_state_for_staged_users.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class DeleteTrackingStateForStagedUsers < ActiveRecord::Migration[6.0]
+  def up
+    execute <<~SQL
+      DELETE FROM category_users
+      WHERE user_id IN (SELECT id FROM users WHERE staged = true)
+    SQL
+
+    execute <<~SQL
+      DELETE FROM tag_users
+      WHERE user_id IN (SELECT id FROM users WHERE staged = true)
+    SQL
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end

GitHub sha: 843bf0df

1 Like

This commit appears in #10083 which was approved by eviltrout. It was merged by SamSaffron.