Fix missing on_delete: :cascade on GeneratedAnnualReport foreign key (#40063)

This commit is contained in:
Claire
2026-08-05 15:56:07 +02:00
committed by GitHub
parent cc6e78984a
commit f49e4f7aa9
3 changed files with 18 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
class CreateGeneratedAnnualReports < ActiveRecord::Migration[7.1]
def change
create_table :generated_annual_reports do |t|
t.belongs_to :account, null: false, foreign_key: { on_cascade: :delete }, index: false
t.belongs_to :account, null: false, foreign_key: true, index: false
t.integer :year, null: false
t.jsonb :data, null: false
t.integer :schema_version, null: false

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
class FixGeneratedAnnualReportsForeignKey < ActiveRecord::Migration[8.1]
def up
safety_assured do
execute 'ALTER TABLE generated_annual_reports DROP CONSTRAINT fk_rails_4ca37f035c, ADD CONSTRAINT fk_rails_4ca37f035c FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE;'
end
end
def down
safety_assured do
execute 'ALTER TABLE generated_annual_reports DROP CONSTRAINT fk_rails_4ca37f035c, ADD CONSTRAINT fk_rails_4ca37f035c FOREIGN KEY (account_id) REFERENCES accounts(id);'
end
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_08_04_081821) do
ActiveRecord::Schema[8.1].define(version: 2026_08_05_130216) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@@ -1551,7 +1551,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_08_04_081821) do
add_foreign_key "follow_requests", "accounts", name: "fk_76d644b0e7", on_delete: :cascade
add_foreign_key "follows", "accounts", column: "target_account_id", name: "fk_745ca29eac", on_delete: :cascade
add_foreign_key "follows", "accounts", name: "fk_32ed1b5560", on_delete: :cascade
add_foreign_key "generated_annual_reports", "accounts"
add_foreign_key "generated_annual_reports", "accounts", on_delete: :cascade
add_foreign_key "global_follow_recommendations", "accounts", on_delete: :cascade
add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade
add_foreign_key "instance_moderation_notes", "accounts", on_delete: :cascade