Skip to content

Commit

Permalink
Add default and constraint to CensorRule#regexp
Browse files Browse the repository at this point in the history
Add default value and not null constraint to `CensorRule#regexp`. While
effectively the same behaviour, this makes the intent explicit and
prevents empty values appearing in admin tables where we render censor
rules.
  • Loading branch information
garethrees committed Mar 13, 2024
1 parent 90def2a commit 146a517
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/models/censor_rule.rb
@@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20210114161442
# Schema version: 20240313094449
#
# Table name: censor_rules
#
Expand All @@ -13,7 +13,7 @@
# last_edit_comment :text not null
# created_at :datetime not null
# updated_at :datetime not null
# regexp :boolean
# regexp :boolean default(FALSE), not null
#

# models/censor_rule.rb:
Expand Down
@@ -0,0 +1,12 @@
class AddNotNullConstraintToCensorRuleRegexp < ActiveRecord::Migration[7.0]
def up
change_column_default :censor_rules, :regexp, false
CensorRule.where(regexp: nil).update_all(regexp: false)
change_column_null :censor_rules, :regexp, false
end

def down
change_column_null :censor_rules, :regexp, true
change_column_default :censor_rules, :regexp, nil
end
end
1 change: 1 addition & 0 deletions doc/CHANGES.md
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Add default value and not null constraint to `CensorRule#regexp` (Gareth Rees)
* Reduce amount of storage related background jobs (Graeme Porteous)
* Add automatic parsing of emails contain Excel spreadsheets (Graeme Porteous)
* Improve rendering of admin hidden request prominence and explanations (Graeme
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/censor_rules.rb
@@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20210114161442
# Schema version: 20240313094449
#
# Table name: censor_rules
#
Expand All @@ -13,7 +13,7 @@
# last_edit_comment :text not null
# created_at :datetime not null
# updated_at :datetime not null
# regexp :boolean
# regexp :boolean default(FALSE), not null
#

FactoryBot.define do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/censor_rule_spec.rb
@@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20210114161442
# Schema version: 20240313094449
#
# Table name: censor_rules
#
Expand All @@ -13,7 +13,7 @@
# last_edit_comment :text not null
# created_at :datetime not null
# updated_at :datetime not null
# regexp :boolean
# regexp :boolean default(FALSE), not null
#

require 'spec_helper'
Expand Down

0 comments on commit 146a517

Please sign in to comment.