0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 01:10:43 +08:00
discourse/db/fixtures/990_settings.rb
David Taylor 2392ff95cd
DEV: Skip backfill INSERTs in old migrations on fresh installs (#39976)
A handful of old migrations unconditionally inserted site_settings or
groups rows that fresh installs already get from YAML defaults or seed
fixtures. This change gates each on `Migration::Helpers.new_site?` (or
drops the redundant insert entirely) so a fresh `db:migrate` leaves no
application-level rows behind:

- `add_revoked_at_to_api_key.rb` no longer inserts
`api_key_last_used_epoch`; `db/fixtures/990_settings.rb` now seeds it
via `SiteSetting.api_key_last_used_epoch ||= Time.now`.
- `fill_personal_message_enabled_groups_based_on_deprecated_settings.rb`
is gated; fresh installs use the YAML default.
- `ensure_anonymous_and_logged_in_users_auto_groups.rb` drops the
`INSERT INTO groups (4, 5, ...)` block —
`Group.ensure_automatic_groups!` in `db/fixtures/002_groups.rb` creates
them. The legacy-group rename portion still runs unconditionally (no-op
on fresh installs anyway).
- chat `add_threads_enabled_site_setting.rb` is gated and the
unconditional `SiteSetting.chat_threads_enabled = false` is replaced
with a raw `INSERT ... ON CONFLICT DO NOTHING` per the migration skill.
- discourse-assign `set_assign_allowed_on_groups_default.rb` is gated;
the YAML `default` is bumped from `""` to `"3"`
(`Group::AUTO_GROUPS[:staff]`) so fresh installs match what the
migration would have written.

Extracted from https://github.com/discourse/discourse/pull/39788.
2026-05-13 13:59:28 +01:00

14 lines
550 B
Ruby
Vendored

# frozen_string_literal: true
if SiteSetting.notification_email == SiteSetting.defaults[:notification_email]
# don't crash for invalid hostname, which is possible in dev
begin
SiteSetting.notification_email = "noreply@#{Discourse.current_hostname}"
rescue Discourse::InvalidParameters
if Rails.env.production?
STDERR.puts "WARNING: Discourse hostname: #{Discourse.current_hostname} is not a valid domain for emails!"
end
end
end
SiteSetting.api_key_last_used_epoch = Time.now if SiteSetting.api_key_last_used_epoch.blank?