mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 03:05:45 +08:00
The original `CreateFlags` migration bumped `flags_id_seq` to 1001 via `setval` so non-system flags get IDs >= 1001, reserving 1-999 for system flags. `pg_dump --schema-only` (which Rails uses to generate `structure.sql`) captures the sequence's `seqstart` metadata but omits runtime `setval` calls. As a result, fresh installs provisioned from `structure.sql` saw the sequence start at 1 instead of 1001. This migration uses `ALTER SEQUENCE ... START WITH` to update the sequence's metadata so the value is preserved in subsequent `structure.sql` dumps. `RESTART` is intentionally omitted: existing sites may already have `last_value` well past 1001, and rewinding would cause id collisions on the next insert.
13 lines
278 B
Ruby
Vendored
13 lines
278 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class FixFlagsIdSeqStart < ActiveRecord::Migration[8.0]
|
|
MAX_SYSTEM_FLAG_ID = 1000
|
|
|
|
def up
|
|
execute "ALTER SEQUENCE flags_id_seq START WITH #{MAX_SYSTEM_FLAG_ID + 1}"
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|