Fix boolean columns sometimes having a null value (#4162)

* Fix boolean columns sometimes having a null value

* Fix wrong value being set instead of null
pull/4181/head
Eugen Rochko 2017-07-13 03:12:25 +02:00 committed by GitHub
parent e48d3bfd01
commit 880a5eb25c
6 changed files with 31 additions and 13 deletions

View File

@ -8,7 +8,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# severity :integer default("silence")
# reject_media :boolean
# reject_media :boolean default(FALSE), not null
#
class DomainBlock < ApplicationRecord

View File

@ -6,7 +6,7 @@
# id :integer not null, primary key
# account_id :integer not null
# type :integer not null
# approved :boolean
# approved :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
# data_file_name :string

View File

@ -12,12 +12,12 @@
# in_reply_to_id :integer
# reblog_of_id :integer
# url :string
# sensitive :boolean default(FALSE)
# sensitive :boolean default(FALSE), not null
# visibility :integer default("public"), not null
# in_reply_to_account_id :integer
# application_id :integer
# spoiler_text :text default(""), not null
# reply :boolean default(FALSE)
# reply :boolean default(FALSE), not null
# favourites_count :integer default(0), not null
# reblogs_count :integer default(0), not null
# language :string
@ -249,6 +249,7 @@ class Status < ApplicationRecord
def set_visibility
self.visibility = (account.locked? ? :private : :public) if visibility.nil?
self.sensitive = false if sensitive.nil?
end
def set_sensitivity

View File

@ -17,7 +17,7 @@
# last_sign_in_at :datetime
# current_sign_in_ip :inet
# last_sign_in_ip :inet
# admin :boolean default(FALSE)
# admin :boolean default(FALSE), not null
# confirmation_token :string
# confirmed_at :datetime
# confirmation_sent_at :datetime
@ -27,7 +27,7 @@
# encrypted_otp_secret_iv :string
# encrypted_otp_secret_salt :string
# consumed_timestep :integer
# otp_required_for_login :boolean
# otp_required_for_login :boolean default(FALSE), not null
# last_emailed_at :datetime
# otp_backup_codes :string is an Array
# filtered_languages :string default([]), not null, is an Array

View File

@ -0,0 +1,17 @@
class FixNullBooleans < ActiveRecord::Migration[5.1]
def change
change_column_default :domain_blocks, :reject_media, false
change_column_null :domain_blocks, :reject_media, false, false
change_column_default :imports, :approved, false
change_column_null :imports, :approved, false, false
change_column_null :statuses, :sensitive, false, false
change_column_null :statuses, :reply, false, false
change_column_null :users, :admin, false, false
change_column_default :users, :otp_required_for_login, false
change_column_null :users, :otp_required_for_login, false, false
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170625140443) do
ActiveRecord::Schema.define(version: 20170711225116) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -89,7 +89,7 @@ ActiveRecord::Schema.define(version: 20170625140443) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "severity", default: 0
t.boolean "reject_media"
t.boolean "reject_media", default: false, null: false
t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true
end
@ -121,7 +121,7 @@ ActiveRecord::Schema.define(version: 20170625140443) do
create_table "imports", id: :serial, force: :cascade do |t|
t.integer "account_id", null: false
t.integer "type", null: false
t.boolean "approved"
t.boolean "approved", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "data_file_name"
@ -281,12 +281,12 @@ ActiveRecord::Schema.define(version: 20170625140443) do
t.bigint "in_reply_to_id"
t.bigint "reblog_of_id"
t.string "url"
t.boolean "sensitive", default: false
t.boolean "sensitive", default: false, null: false
t.integer "visibility", default: 0, null: false
t.integer "in_reply_to_account_id"
t.integer "application_id"
t.text "spoiler_text", default: "", null: false
t.boolean "reply", default: false
t.boolean "reply", default: false, null: false
t.integer "favourites_count", default: 0, null: false
t.integer "reblogs_count", default: 0, null: false
t.string "language"
@ -350,7 +350,7 @@ ActiveRecord::Schema.define(version: 20170625140443) do
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.boolean "admin", default: false
t.boolean "admin", default: false, null: false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
@ -360,7 +360,7 @@ ActiveRecord::Schema.define(version: 20170625140443) do
t.string "encrypted_otp_secret_iv"
t.string "encrypted_otp_secret_salt"
t.integer "consumed_timestep"
t.boolean "otp_required_for_login"
t.boolean "otp_required_for_login", default: false, null: false
t.datetime "last_emailed_at"
t.string "otp_backup_codes", array: true
t.string "filtered_languages", default: [], null: false, array: true