1 class AddCheckConstraintToRedactionTitleAndDescription < ActiveRecord::Migration[7.1]
 
   2   disable_ddl_transaction!
 
   5     Redaction.where(:title => nil).find_in_batches(:batch_size => 1000) do |redactions|
 
   7         r.title = "Redaction #{r.id}"
 
   8         r.save!(:validate => false)
 
  12     Redaction.where(:description => nil).find_in_batches(:batch_size => 1000) do |redactions|
 
  13       redactions.each { |r| r.update!(:description => "No description") }
 
  16     add_check_constraint :redactions, "title IS NOT NULL", :name => "redaction_title_not_null", :validate => false
 
  17     add_check_constraint :redactions, "description IS NOT NULL", :name => "redaction_description_not_null", :validate => false
 
  21     remove_check_constraint :redactions, :name => "redaction_title_not_null", :if_exists => true
 
  22     remove_check_constraint :redactions, :name => "redaction_description_not_null", :if_exists => true