discourse/app/models/directory_column.rb
David Taylor 3332e9f4c3
DEV: Always pass --force to annotaterb and reorder annotations (#39977)
`.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.
2026-05-13 14:12:48 +01:00

75 lines
1.8 KiB
Ruby

# frozen_string_literal: true
class DirectoryColumn < ActiveRecord::Base
self.inheritance_column = nil
enum :type, { automatic: 0, user_field: 1, plugin: 2 }, scopes: false
def self.automatic_column_names
@automatic_column_names ||= %i[
likes_received
likes_given
topics_entered
topic_count
post_count
posts_read
days_visited
]
end
def self.active_column_names
DirectoryColumn
.where(type: %i[automatic plugin])
.where(enabled: true)
.pluck(:name)
.map(&:to_sym)
end
@@plugin_directory_columns = []
def self.plugin_directory_columns
@@plugin_directory_columns
end
belongs_to :user_field
def self.clear_plugin_directory_columns
@@plugin_directory_columns = []
end
def self.find_or_create_plugin_directory_column(attrs)
directory_column =
find_or_create_by(
name: attrs[:column_name],
icon: attrs[:icon],
type: DirectoryColumn.types[:plugin],
) do |column|
column.position = DirectoryColumn.maximum("position") + 1
column.enabled = false
end
if @@plugin_directory_columns.exclude?(directory_column.name)
@@plugin_directory_columns << directory_column.name
DirectoryItem.add_plugin_query(attrs[:query])
end
end
end
# == Schema Information
#
# Table name: directory_columns
#
# id :bigint not null, primary key
# automatic_position :integer
# enabled :boolean not null
# icon :string
# name :string
# position :integer not null
# type :integer default("automatic"), not null
# created_at :datetime
# user_field_id :integer
#
# Indexes
#
# directory_column_index (enabled,position,user_field_id)
#