mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-22 12:55:56 +01:00
Add missing NOT NULL
on more columns from "large but valid" tables (#33330)
This commit is contained in:
parent
f19fd0b889
commit
978142ac9e
17 changed files with 173 additions and 17 deletions
|
@ -5,11 +5,11 @@
|
|||
# Table name: account_notes
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# target_account_id :bigint(8)
|
||||
# comment :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
# target_account_id :bigint(8) not null
|
||||
#
|
||||
class AccountNote < ApplicationRecord
|
||||
include RelationshipCacheable
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
# Table name: markers
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# user_id :bigint(8)
|
||||
# timeline :string default(""), not null
|
||||
# last_read_id :bigint(8) default(0), not null
|
||||
# lock_version :integer default(0), not null
|
||||
# timeline :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# last_read_id :bigint(8) default(0), not null
|
||||
# user_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class Marker < ApplicationRecord
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
# Table name: poll_votes
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# poll_id :bigint(8)
|
||||
# choice :integer default(0), not null
|
||||
# uri :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# uri :string
|
||||
# account_id :bigint(8) not null
|
||||
# poll_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class PollVote < ApplicationRecord
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
# Table name: tombstones
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# by_moderator :boolean
|
||||
# uri :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# by_moderator :boolean
|
||||
# account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class Tombstone < ApplicationRecord
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToAccountNoteAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :account_notes, 'account_id IS NOT NULL', name: 'account_notes_account_id_null', validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToAccountNoteAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM account_notes
|
||||
WHERE account_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :account_notes, name: 'account_notes_account_id_null'
|
||||
change_column_null :account_notes, :account_id, false
|
||||
remove_check_constraint :account_notes, name: 'account_notes_account_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :account_notes, 'account_id IS NOT NULL', name: 'account_notes_account_id_null', validate: false
|
||||
change_column_null :account_notes, :account_id, true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToAccountNoteTargetAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :account_notes, 'target_account_id IS NOT NULL', name: 'account_notes_target_account_id_null', validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToAccountNoteTargetAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM account_notes
|
||||
WHERE target_account_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :account_notes, name: 'account_notes_target_account_id_null'
|
||||
change_column_null :account_notes, :target_account_id, false
|
||||
remove_check_constraint :account_notes, name: 'account_notes_target_account_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :account_notes, 'target_account_id IS NOT NULL', name: 'account_notes_target_account_id_null', validate: false
|
||||
change_column_null :account_notes, :target_account_id, true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToMarkerUserColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :markers, 'user_id IS NOT NULL', name: 'markers_user_id_null', validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToMarkerUserColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM markers
|
||||
WHERE user_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :markers, name: 'markers_user_id_null'
|
||||
change_column_null :markers, :user_id, false
|
||||
remove_check_constraint :markers, name: 'markers_user_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :markers, 'user_id IS NOT NULL', name: 'markers_user_id_null', validate: false
|
||||
change_column_null :markers, :user_id, true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToPollVoteAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :poll_votes, 'account_id IS NOT NULL', name: 'poll_votes_account_id_null', validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToPollVoteAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM poll_votes
|
||||
WHERE account_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :poll_votes, name: 'poll_votes_account_id_null'
|
||||
change_column_null :poll_votes, :account_id, false
|
||||
remove_check_constraint :poll_votes, name: 'poll_votes_account_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :poll_votes, 'account_id IS NOT NULL', name: 'poll_votes_account_id_null', validate: false
|
||||
change_column_null :poll_votes, :account_id, true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToPollVotePollColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :poll_votes, 'poll_id IS NOT NULL', name: 'poll_votes_poll_id_null', validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToPollVotePollColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM poll_votes
|
||||
WHERE poll_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :poll_votes, name: 'poll_votes_poll_id_null'
|
||||
change_column_null :poll_votes, :poll_id, false
|
||||
remove_check_constraint :poll_votes, name: 'poll_votes_poll_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :poll_votes, 'poll_id IS NOT NULL', name: 'poll_votes_poll_id_null', validate: false
|
||||
change_column_null :poll_votes, :poll_id, true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToTombstoneAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :tombstones, 'account_id IS NOT NULL', name: 'tombstones_account_id_null', validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToTombstoneAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM tombstones
|
||||
WHERE account_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :tombstones, name: 'tombstones_account_id_null'
|
||||
change_column_null :tombstones, :account_id, false
|
||||
remove_check_constraint :tombstones, name: 'tombstones_account_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :tombstones, 'account_id IS NOT NULL', name: 'tombstones_account_id_null', validate: false
|
||||
change_column_null :tombstones, :account_id, true
|
||||
end
|
||||
end
|
14
db/schema.rb
14
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_12_13_170053) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_12_16_224825) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -72,8 +72,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_13_170053) do
|
|||
end
|
||||
|
||||
create_table "account_notes", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.bigint "target_account_id"
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "target_account_id", null: false
|
||||
t.text "comment", null: false
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
|
@ -599,7 +599,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_13_170053) do
|
|||
end
|
||||
|
||||
create_table "markers", force: :cascade do |t|
|
||||
t.bigint "user_id"
|
||||
t.bigint "user_id", null: false
|
||||
t.string "timeline", default: "", null: false
|
||||
t.bigint "last_read_id", default: 0, null: false
|
||||
t.integer "lock_version", default: 0, null: false
|
||||
|
@ -767,8 +767,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_13_170053) do
|
|||
end
|
||||
|
||||
create_table "poll_votes", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.bigint "poll_id"
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "poll_id", null: false
|
||||
t.integer "choice", default: 0, null: false
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
|
@ -1113,7 +1113,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_13_170053) do
|
|||
end
|
||||
|
||||
create_table "tombstones", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.bigint "account_id", null: false
|
||||
t.string "uri", null: false
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
|
|
Loading…
Reference in a new issue