mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-14 11:08:51 +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.
40 lines
1.2 KiB
Ruby
40 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
class AssociatedGroup < ActiveRecord::Base
|
|
has_many :user_associated_groups, dependent: :destroy
|
|
has_many :users, through: :user_associated_groups
|
|
has_many :group_associated_groups, dependent: :destroy
|
|
has_many :groups, through: :group_associated_groups
|
|
|
|
def label
|
|
"#{provider_name}:#{name}"
|
|
end
|
|
|
|
def self.has_provider?
|
|
Discourse.enabled_authenticators.any? { |a| a.provides_groups? }
|
|
end
|
|
|
|
def self.cleanup!
|
|
AssociatedGroup
|
|
.left_joins(:group_associated_groups, :user_associated_groups)
|
|
.where("group_associated_groups.id IS NULL AND user_associated_groups.id IS NULL")
|
|
.where("last_used < ?", 1.week.ago)
|
|
.delete_all
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: associated_groups
|
|
#
|
|
# id :bigint not null, primary key
|
|
# last_used :datetime not null
|
|
# name :string not null
|
|
# provider_name :string not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# provider_id :string not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# associated_groups_provider_id (provider_name,provider_id) UNIQUE
|
|
#
|