FIX: Migration to set column NOT NULL for delete_when_reminder_sent on bookmarks (#9696)

FIX: Migration to set column NOT NULL for delete_when_reminder_sent on bookmarks (#9696)

Also fix typo in original migration.

Meta: Improved Bookmarks with Reminders - announcements - Discourse Meta

diff --git a/db/migrate/20200505060712_add_delete_when_reminder_sent_boolean_to_bookmarks.rb b/db/migrate/20200505060712_add_delete_when_reminder_sent_boolean_to_bookmarks.rb
index 7e4ca80..66976ff 100644
--- a/db/migrate/20200505060712_add_delete_when_reminder_sent_boolean_to_bookmarks.rb
+++ b/db/migrate/20200505060712_add_delete_when_reminder_sent_boolean_to_bookmarks.rb
@@ -2,6 +2,6 @@
 
 class AddDeleteWhenReminderSentBooleanToBookmarks < ActiveRecord::Migration[6.0]
   def change
-    add_column :bookmarks, :delete_when_reminder_sent, :boolean, nullabe: false, default: false
+    add_column :bookmarks, :delete_when_reminder_sent, :boolean, null: false, default: false
   end
 end
diff --git a/db/migrate/20200507234409_ensure_bookmark_delete_when_reminder_sent_not_null.rb b/db/migrate/20200507234409_ensure_bookmark_delete_when_reminder_sent_not_null.rb
new file mode 100644
index 0000000..5052675
--- /dev/null
+++ b/db/migrate/20200507234409_ensure_bookmark_delete_when_reminder_sent_not_null.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class EnsureBookmarkDeleteWhenReminderSentNotNull < ActiveRecord::Migration[6.0]
+  def change
+    DB.exec("UPDATE bookmarks SET delete_when_reminder_sent = false WHERE delete_when_reminder_sent IS NULL")
+    change_column_null :bookmarks, :delete_when_reminder_sent, false
+  end
+end

GitHub sha: e83dc752

This commit appears in #9696 which was merged by martin.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/improved-bookmarks-with-reminders/144542/163