Merge remote-tracking branch 'upstream/pull/4566'
This commit is contained in:
commit
c91bd55222
5 changed files with 62 additions and 4 deletions
|
@ -3,8 +3,8 @@
|
|||
# Table name: redactions
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# title :string
|
||||
# description :text
|
||||
# title :string not null
|
||||
# description :text not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# user_id :bigint(8) not null
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
class AddCheckConstraintToRedactionTitleAndDescription < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
Redaction.where(:title => nil).find_in_batches(:batch_size => 1000) do |redactions|
|
||||
redactions.each do |r|
|
||||
r.title = "Redaction #{r.id}"
|
||||
r.save!(:validate => false)
|
||||
end
|
||||
end
|
||||
|
||||
Redaction.where(:description => nil).find_in_batches(:batch_size => 1000) do |redactions|
|
||||
redactions.each { |r| r.update!(:description => "No description") }
|
||||
end
|
||||
|
||||
add_check_constraint :redactions, "title IS NOT NULL", :name => "redaction_title_not_null", :validate => false
|
||||
add_check_constraint :redactions, "description IS NOT NULL", :name => "redaction_description_not_null", :validate => false
|
||||
end
|
||||
|
||||
def down
|
||||
remove_check_constraint :redactions, :name => "redaction_title_not_null", :if_exists => true
|
||||
remove_check_constraint :redactions, :name => "redaction_description_not_null", :if_exists => true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
class ValidateAndModifyRedactionTitleAndDescription < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
validate_check_constraint :redactions, :name => "redaction_title_not_null"
|
||||
validate_check_constraint :redactions, :name => "redaction_description_not_null"
|
||||
|
||||
change_column_null :redactions, :title, false
|
||||
change_column_null :redactions, :description, false
|
||||
|
||||
remove_check_constraint :redactions, :name => "redaction_title_not_null"
|
||||
remove_check_constraint :redactions, :name => "redaction_description_not_null"
|
||||
end
|
||||
|
||||
def down
|
||||
change_column_null :redactions, :title, true
|
||||
change_column_null :redactions, :description, true
|
||||
end
|
||||
end
|
|
@ -1304,8 +1304,8 @@ ALTER SEQUENCE public.oauth_tokens_id_seq OWNED BY public.oauth_tokens.id;
|
|||
|
||||
CREATE TABLE public.redactions (
|
||||
id integer NOT NULL,
|
||||
title character varying,
|
||||
description text,
|
||||
title character varying NOT NULL,
|
||||
description text NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
user_id bigint NOT NULL,
|
||||
|
@ -3512,6 +3512,8 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('23'),
|
||||
('22'),
|
||||
('21'),
|
||||
('20240307181018'),
|
||||
('20240307180830'),
|
||||
('20240228205723'),
|
||||
('20240117185445'),
|
||||
('20231213182102'),
|
||||
|
@ -3597,3 +3599,4 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('11'),
|
||||
('10'),
|
||||
('1');
|
||||
|
||||
|
|
|
@ -33,4 +33,16 @@ class RedactionTest < ActiveSupport::TestCase
|
|||
assert_predicate(node_v1, :redacted?, "Expected node version 1 to be redacted after redact! call.")
|
||||
assert_not_predicate(node_v2, :redacted?, "Expected node version 2 to not be redacted after redact! call.")
|
||||
end
|
||||
|
||||
def test_invalid_with_empty_title
|
||||
redaction = build(:redaction, :title => "")
|
||||
assert_not redaction.valid?
|
||||
assert_includes redaction.errors.messages[:title], "can't be blank"
|
||||
end
|
||||
|
||||
def test_invalid_with_empty_description
|
||||
redaction = build(:redaction, :description => "")
|
||||
assert_not redaction.valid?
|
||||
assert_includes redaction.errors.messages[:description], "can't be blank"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue