mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 13:25:19 +08:00
Previously, `20131022045114_add_uncategorized_category.rb` always created an Uncategorized category and wrote the matching `uncategorized_category_id` site setting, duplicating work that `db/fixtures/500_categories.rb` (via `SeedData::Categories`) already does on every fresh install. This change gates the insert/update block on whether any category-less regular topics exist — the only case where the migration genuinely needs to backfill before the CHECK constraint can be added. The `ALTER TABLE … ADD CONSTRAINT has_category_id` still runs unconditionally so the schema is identical on both paths. Two later migrations (`20140715190552_remove_uncategorized_parents.rb` and `20150818190757_create_embeddable_hosts.rb`) read `uncategorized_category_id` via `PG::Result#[](0)`, which raises `IndexError` rather than returning `nil` when the row is missing — previously dormant because the original migration always wrote the setting. They are updated here to guard with `cmd_tuples`/`ntuples` before indexing. Extracted from https://github.com/discourse/discourse/pull/39788.
10 lines
309 B
Ruby
Vendored
10 lines
309 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
require "seed_data/categories"
|
|
|
|
if Rails.env.test?
|
|
# Tests need the Uncategorized category, but none of the others.
|
|
SeedData::Categories.with_default_locale.create(site_setting_names: ["uncategorized_category_id"])
|
|
else
|
|
SeedData::Categories.with_default_locale.create
|
|
end
|