mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-16 01:40:15 +08:00
`.annotaterb.yml` has carried `classified_sort: true` since the project
switched from `annotate` to `annotaterb` (commit 0eab7daea4, July 2025),
but annotaterb's default behaviour is to compare the existing schema
block against what it would generate and skip the rewrite when the
column list matches — even when the *ordering* of those columns differs.
The result is that models which haven't had a schema change since the
config landed never get reordered, and `classified_sort` drift
accumulates indefinitely.
`--force` makes annotaterb always rewrite, so a single `bin/rake
annotate:clean` run brings every model into the canonical format and
keeps them there. Every schema block is now grouped primary-key →
regular columns → timestamps → foreign keys (alphabetical within each
group). Pure annotation comment change — no code modifications.
Also cleans up the rake task to avoid string interpolation for `system`
calls.
61 lines
1.5 KiB
Ruby
61 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class DraftSequence < ActiveRecord::Base
|
|
def self.next!(user, key)
|
|
return nil if !user
|
|
|
|
user_id = user
|
|
user_id = user.id unless user.is_a?(Integer)
|
|
|
|
return 0 if !User.human_user_id?(user_id)
|
|
|
|
sequence = DB.query_single(<<~SQL, user_id: user_id, draft_key: key).first
|
|
INSERT INTO draft_sequences (user_id, draft_key, sequence)
|
|
VALUES (:user_id, :draft_key, 1)
|
|
ON CONFLICT (user_id, draft_key) DO
|
|
UPDATE
|
|
SET sequence = draft_sequences.sequence + 1
|
|
WHERE draft_sequences.user_id = :user_id
|
|
AND draft_sequences.draft_key = :draft_key
|
|
RETURNING sequence
|
|
SQL
|
|
|
|
Draft.where(user_id: user_id, draft_key: key).destroy_all
|
|
|
|
UserStat.update_draft_count(user_id)
|
|
|
|
sequence
|
|
end
|
|
|
|
def self.current(user, key)
|
|
return nil if !user
|
|
|
|
user_id = user
|
|
user_id = user.id unless user.is_a?(Integer)
|
|
|
|
return 0 if !User.human_user_id?(user_id)
|
|
|
|
# perf critical path
|
|
r, _ =
|
|
DB.query_single(
|
|
"select sequence from draft_sequences where user_id = ? and draft_key = ?",
|
|
user_id,
|
|
key,
|
|
)
|
|
r.to_i
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: draft_sequences
|
|
#
|
|
# id :integer not null, primary key
|
|
# draft_key :string not null
|
|
# sequence :bigint not null
|
|
# user_id :integer not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_draft_sequences_on_user_id_and_draft_key (user_id,draft_key) UNIQUE
|
|
#
|