diff --git a/app/models/account_alias.rb b/app/models/account_alias.rb index 41623ddedb..af156f1497 100644 --- a/app/models/account_alias.rb +++ b/app/models/account_alias.rb @@ -5,11 +5,11 @@ # Table name: account_aliases # # id :bigint(8) not null, primary key -# account_id :bigint(8) # acct :string default(""), not null # uri :string default(""), not null # created_at :datetime not null # updated_at :datetime not null +# account_id :bigint(8) not null # class AccountAlias < ApplicationRecord diff --git a/app/models/account_deletion_request.rb b/app/models/account_deletion_request.rb index 7d0c346cc2..c65d2cc217 100644 --- a/app/models/account_deletion_request.rb +++ b/app/models/account_deletion_request.rb @@ -5,9 +5,9 @@ # Table name: account_deletion_requests # # id :bigint(8) not null, primary key -# account_id :bigint(8) # created_at :datetime not null # updated_at :datetime not null +# account_id :bigint(8) not null # class AccountDeletionRequest < ApplicationRecord DELAY_TO_DELETION = 30.days.freeze diff --git a/app/models/account_domain_block.rb b/app/models/account_domain_block.rb index 753935d6af..c3a8c49da0 100644 --- a/app/models/account_domain_block.rb +++ b/app/models/account_domain_block.rb @@ -5,10 +5,10 @@ # Table name: account_domain_blocks # # id :bigint(8) not null, primary key -# domain :string +# domain :string not null # created_at :datetime not null # updated_at :datetime not null -# account_id :bigint(8) +# account_id :bigint(8) not null # class AccountDomainBlock < ApplicationRecord diff --git a/app/models/admin/action_log.rb b/app/models/admin/action_log.rb index 49ae679809..b6834c4784 100644 --- a/app/models/admin/action_log.rb +++ b/app/models/admin/action_log.rb @@ -5,15 +5,15 @@ # Table name: admin_action_logs # # id :bigint(8) not null, primary key -# account_id :bigint(8) # action :string default(""), not null +# human_identifier :string +# permalink :string +# route_param :string # target_type :string -# target_id :bigint(8) # created_at :datetime not null # updated_at :datetime not null -# human_identifier :string -# route_param :string -# permalink :string +# account_id :bigint(8) not null +# target_id :bigint(8) # class Admin::ActionLog < ApplicationRecord diff --git a/app/models/announcement_mute.rb b/app/models/announcement_mute.rb index 46fda2f5d6..0f34a6a4dc 100644 --- a/app/models/announcement_mute.rb +++ b/app/models/announcement_mute.rb @@ -5,10 +5,10 @@ # Table name: announcement_mutes # # id :bigint(8) not null, primary key -# account_id :bigint(8) -# announcement_id :bigint(8) # created_at :datetime not null # updated_at :datetime not null +# account_id :bigint(8) not null +# announcement_id :bigint(8) not null # class AnnouncementMute < ApplicationRecord diff --git a/app/models/announcement_reaction.rb b/app/models/announcement_reaction.rb index f953402b7e..46d9fc290f 100644 --- a/app/models/announcement_reaction.rb +++ b/app/models/announcement_reaction.rb @@ -5,12 +5,12 @@ # Table name: announcement_reactions # # id :bigint(8) not null, primary key -# account_id :bigint(8) -# announcement_id :bigint(8) # name :string default(""), not null -# custom_emoji_id :bigint(8) # created_at :datetime not null # updated_at :datetime not null +# account_id :bigint(8) not null +# announcement_id :bigint(8) not null +# custom_emoji_id :bigint(8) # class AnnouncementReaction < ApplicationRecord diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index bacf158261..a351a140a0 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -5,13 +5,13 @@ # Table name: custom_filters # # id :bigint(8) not null, primary key -# account_id :bigint(8) +# action :integer default("warn"), not null +# context :string default([]), not null, is an Array # expires_at :datetime # phrase :text default(""), not null -# context :string default([]), not null, is an Array # created_at :datetime not null # updated_at :datetime not null -# action :integer default("warn"), not null +# account_id :bigint(8) not null # class CustomFilter < ApplicationRecord diff --git a/app/models/scheduled_status.rb b/app/models/scheduled_status.rb index cb49e90705..1f4f04268d 100644 --- a/app/models/scheduled_status.rb +++ b/app/models/scheduled_status.rb @@ -5,9 +5,9 @@ # Table name: scheduled_statuses # # id :bigint(8) not null, primary key -# account_id :bigint(8) -# scheduled_at :datetime # params :jsonb +# scheduled_at :datetime +# account_id :bigint(8) not null # class ScheduledStatus < ApplicationRecord diff --git a/app/models/user_invite_request.rb b/app/models/user_invite_request.rb index 9dd6775166..23b5428d48 100644 --- a/app/models/user_invite_request.rb +++ b/app/models/user_invite_request.rb @@ -5,10 +5,10 @@ # Table name: user_invite_requests # # id :bigint(8) not null, primary key -# user_id :bigint(8) # text :text # created_at :datetime not null # updated_at :datetime not null +# user_id :bigint(8) not null # class UserInviteRequest < ApplicationRecord diff --git a/db/migrate/20241212152158_add_not_null_to_account_alias_columns.rb b/db/migrate/20241212152158_add_not_null_to_account_alias_columns.rb new file mode 100644 index 0000000000..cd57f3b2fa --- /dev/null +++ b/db/migrate/20241212152158_add_not_null_to_account_alias_columns.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNotNullToAccountAliasColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM account_aliases + WHERE account_id IS NULL + SQL + + safety_assured { change_column_null :account_aliases, :account_id, false } + end + + def down + safety_assured { change_column_null :account_aliases, :account_id, true } + end +end diff --git a/db/migrate/20241212152618_add_not_null_to_account_deletion_request_columns.rb b/db/migrate/20241212152618_add_not_null_to_account_deletion_request_columns.rb new file mode 100644 index 0000000000..80c57b1e39 --- /dev/null +++ b/db/migrate/20241212152618_add_not_null_to_account_deletion_request_columns.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNotNullToAccountDeletionRequestColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM account_deletion_requests + WHERE account_id IS NULL + SQL + + safety_assured { change_column_null :account_deletion_requests, :account_id, false } + end + + def down + safety_assured { change_column_null :account_deletion_requests, :account_id, true } + end +end diff --git a/db/migrate/20241212152734_add_not_null_to_account_domain_block_columns.rb b/db/migrate/20241212152734_add_not_null_to_account_domain_block_columns.rb new file mode 100644 index 0000000000..38ab6b9ad4 --- /dev/null +++ b/db/migrate/20241212152734_add_not_null_to_account_domain_block_columns.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddNotNullToAccountDomainBlockColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM account_domain_blocks + WHERE account_id IS NULL + OR domain IS NULL + SQL + + safety_assured do + change_column_null :account_domain_blocks, :account_id, false + change_column_null :account_domain_blocks, :domain, false + end + end + + def down + safety_assured do + change_column_null :account_domain_blocks, :account_id, true + change_column_null :account_domain_blocks, :domain, true + end + end +end diff --git a/db/migrate/20241212152910_add_not_null_to_admin_action_log_columns.rb b/db/migrate/20241212152910_add_not_null_to_admin_action_log_columns.rb new file mode 100644 index 0000000000..092ad00e85 --- /dev/null +++ b/db/migrate/20241212152910_add_not_null_to_admin_action_log_columns.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNotNullToAdminActionLogColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM admin_action_logs + WHERE account_id IS NULL + SQL + + safety_assured { change_column_null :admin_action_logs, :account_id, false } + end + + def down + safety_assured { change_column_null :admin_action_logs, :account_id, true } + end +end diff --git a/db/migrate/20241212153054_add_not_null_to_announcement_mute_columns.rb b/db/migrate/20241212153054_add_not_null_to_announcement_mute_columns.rb new file mode 100644 index 0000000000..052f0300a9 --- /dev/null +++ b/db/migrate/20241212153054_add_not_null_to_announcement_mute_columns.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddNotNullToAnnouncementMuteColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM announcement_mutes + WHERE account_id IS NULL + OR announcement_id IS NULL + SQL + + safety_assured do + change_column_null :announcement_mutes, :account_id, false + change_column_null :announcement_mutes, :announcement_id, false + end + end + + def down + safety_assured do + change_column_null :announcement_mutes, :account_id, true + change_column_null :announcement_mutes, :announcement_id, true + end + end +end diff --git a/db/migrate/20241212153202_add_not_null_to_announcement_reaction_columns.rb b/db/migrate/20241212153202_add_not_null_to_announcement_reaction_columns.rb new file mode 100644 index 0000000000..a877eccb3a --- /dev/null +++ b/db/migrate/20241212153202_add_not_null_to_announcement_reaction_columns.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddNotNullToAnnouncementReactionColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM announcement_reactions + WHERE account_id IS NULL + OR announcement_id IS NULL + SQL + + safety_assured do + change_column_null :announcement_reactions, :account_id, false + change_column_null :announcement_reactions, :announcement_id, false + end + end + + def down + safety_assured do + change_column_null :announcement_reactions, :account_id, true + change_column_null :announcement_reactions, :announcement_id, true + end + end +end diff --git a/db/migrate/20241212153254_add_not_null_to_custom_filter_columns.rb b/db/migrate/20241212153254_add_not_null_to_custom_filter_columns.rb new file mode 100644 index 0000000000..5eeb5f942a --- /dev/null +++ b/db/migrate/20241212153254_add_not_null_to_custom_filter_columns.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNotNullToCustomFilterColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM custom_filters + WHERE account_id IS NULL + SQL + + safety_assured { change_column_null :custom_filters, :account_id, false } + end + + def down + safety_assured { change_column_null :custom_filters, :account_id, true } + end +end diff --git a/db/migrate/20241212154231_add_not_null_to_scheduled_status_columns.rb b/db/migrate/20241212154231_add_not_null_to_scheduled_status_columns.rb new file mode 100644 index 0000000000..141b95b63a --- /dev/null +++ b/db/migrate/20241212154231_add_not_null_to_scheduled_status_columns.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNotNullToScheduledStatusColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM scheduled_statuses + WHERE account_id IS NULL + SQL + + safety_assured { change_column_null :scheduled_statuses, :account_id, false } + end + + def down + safety_assured { change_column_null :scheduled_statuses, :account_id, true } + end +end diff --git a/db/migrate/20241212154346_add_not_null_to_user_invite_request_columns.rb b/db/migrate/20241212154346_add_not_null_to_user_invite_request_columns.rb new file mode 100644 index 0000000000..7066f69691 --- /dev/null +++ b/db/migrate/20241212154346_add_not_null_to_user_invite_request_columns.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNotNullToUserInviteRequestColumns < ActiveRecord::Migration[7.2] + def up + connection.execute(<<~SQL.squish) + DELETE FROM user_invite_requests + WHERE user_id IS NULL + SQL + + safety_assured { change_column_null :user_invite_requests, :user_id, false } + end + + def down + safety_assured { change_column_null :user_invite_requests, :user_id, true } + end +end diff --git a/db/schema.rb b/db/schema.rb index f7f6cf63b3..2a7684d5df 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,12 +10,12 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do +ActiveRecord::Schema[7.2].define(version: 2024_12_12_154346) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "account_aliases", force: :cascade do |t| - t.bigint "account_id" + t.bigint "account_id", null: false t.string "acct", default: "", null: false t.string "uri", default: "", null: false t.datetime "created_at", precision: nil, null: false @@ -36,17 +36,17 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do end create_table "account_deletion_requests", force: :cascade do |t| - t.bigint "account_id" + t.bigint "account_id", null: false t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_account_deletion_requests_on_account_id" end create_table "account_domain_blocks", force: :cascade do |t| - t.string "domain" + t.string "domain", null: false t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false - t.bigint "account_id" + t.bigint "account_id", null: false t.index ["account_id", "domain"], name: "index_account_domain_blocks_on_account_id_and_domain", unique: true end @@ -213,7 +213,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do end create_table "admin_action_logs", force: :cascade do |t| - t.bigint "account_id" + t.bigint "account_id", null: false t.string "action", default: "", null: false t.string "target_type" t.bigint "target_id" @@ -227,8 +227,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do end create_table "announcement_mutes", force: :cascade do |t| - t.bigint "account_id" - t.bigint "announcement_id" + t.bigint "account_id", null: false + t.bigint "announcement_id", null: false t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.index ["account_id", "announcement_id"], name: "index_announcement_mutes_on_account_id_and_announcement_id", unique: true @@ -236,8 +236,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do end create_table "announcement_reactions", force: :cascade do |t| - t.bigint "account_id" - t.bigint "announcement_id" + t.bigint "account_id", null: false + t.bigint "announcement_id", null: false t.string "name", default: "", null: false t.bigint "custom_emoji_id" t.datetime "created_at", precision: nil, null: false @@ -405,7 +405,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do end create_table "custom_filters", force: :cascade do |t| - t.bigint "account_id" + t.bigint "account_id", null: false t.datetime "expires_at", precision: nil t.text "phrase", default: "", null: false t.string "context", default: [], null: false, array: true @@ -915,7 +915,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do end create_table "scheduled_statuses", force: :cascade do |t| - t.bigint "account_id" + t.bigint "account_id", null: false t.datetime "scheduled_at", precision: nil t.jsonb "params" t.index ["account_id"], name: "index_scheduled_statuses_on_account_id" @@ -1130,7 +1130,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do end create_table "user_invite_requests", force: :cascade do |t| - t.bigint "user_id" + t.bigint "user_id", null: false t.text "text" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false