]> git.openstreetmap.org Git - rails.git/blob - db/migrate/20240307180830_add_check_constraint_to_redaction_title_and_description.rb
Add frozen_string_literal comments to ruby files
[rails.git] / db / migrate / 20240307180830_add_check_constraint_to_redaction_title_and_description.rb
1 # frozen_string_literal: true
2
3 class AddCheckConstraintToRedactionTitleAndDescription < ActiveRecord::Migration[7.1]
4   disable_ddl_transaction!
5
6   def up
7     Redaction.where(:title => nil).find_in_batches(:batch_size => 1000) do |redactions|
8       redactions.each do |r|
9         r.title = "Redaction #{r.id}"
10         r.save!(:validate => false)
11       end
12     end
13
14     Redaction.where(:description => nil).find_in_batches(:batch_size => 1000) do |redactions|
15       redactions.each { |r| r.update!(:description => "No description") }
16     end
17
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
20   end
21
22   def down
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
25   end
26 end