discourse/db/migrate/20260518054805_fix_flags_id_seq_start.rb
Krzysztof Kotlarek 67305dc7bb
DEV: Persist flags_id_seq start value in structure.sql (#40109)
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.
2026-05-18 17:13:40 +08:00

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