1 # frozen_string_literal: true
 
   3 class AddCheckConstraintToRedactionTitleAndDescription < ActiveRecord::Migration[7.1]
 
   4   disable_ddl_transaction!
 
   7     Redaction.where(:title => nil).find_in_batches(:batch_size => 1000) do |redactions|
 
   9         r.title = "Redaction #{r.id}"
 
  10         r.save!(:validate => false)
 
  14     Redaction.where(:description => nil).find_in_batches(:batch_size => 1000) do |redactions|
 
  15       redactions.each { |r| r.update!(:description => "No description") }
 
  18     add_check_constraint :redactions, "title IS NOT NULL", :name => "redaction_title_not_null", :validate => false
 
  19     add_check_constraint :redactions, "description IS NOT NULL", :name => "redaction_description_not_null", :validate => false
 
  23     remove_check_constraint :redactions, :name => "redaction_title_not_null", :if_exists => true
 
  24     remove_check_constraint :redactions, :name => "redaction_description_not_null", :if_exists => true