mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-26 09:28:35 +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.
72 lines
1.7 KiB
Ruby
Vendored
72 lines
1.7 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class UnsubscribeKey < ActiveRecord::Base
|
|
belongs_to :user
|
|
belongs_to :post
|
|
belongs_to :topic
|
|
|
|
before_create :generate_random_key
|
|
|
|
ALL_TYPE = "all"
|
|
DIGEST_TYPE = "digest"
|
|
TOPIC_TYPE = "topic"
|
|
|
|
class << self
|
|
def create_key_for(user, type, post: nil)
|
|
unsubscribe_key = new(user_id: user.id, unsubscribe_key_type: type)
|
|
|
|
if type == TOPIC_TYPE
|
|
unsubscribe_key.topic_id = post.topic_id
|
|
unsubscribe_key.post_id = post.id
|
|
end
|
|
|
|
unsubscribe_key.save!
|
|
unsubscribe_key.key
|
|
end
|
|
|
|
def user_for_key(key)
|
|
where(key: key).first&.user
|
|
end
|
|
|
|
def get_unsubscribe_strategy_for(key)
|
|
strategies = {
|
|
DIGEST_TYPE => EmailControllerHelper::DigestEmailUnsubscriber,
|
|
TOPIC_TYPE => EmailControllerHelper::TopicEmailUnsubscriber,
|
|
ALL_TYPE => EmailControllerHelper::BaseEmailUnsubscriber,
|
|
}
|
|
|
|
DiscoursePluginRegistry.email_unsubscribers.each do |unsubcriber|
|
|
strategies.merge!(unsubcriber)
|
|
end
|
|
|
|
strategies[key.unsubscribe_key_type]&.new(key)
|
|
end
|
|
end
|
|
|
|
def associated_topic
|
|
@associated_topic ||= topic || post&.topic
|
|
end
|
|
|
|
private
|
|
|
|
def generate_random_key
|
|
self.key = SecureRandom.hex(32)
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: unsubscribe_keys
|
|
#
|
|
# key :string(64) not null, primary key
|
|
# unsubscribe_key_type :string
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# post_id :integer
|
|
# topic_id :integer
|
|
# user_id :integer not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_unsubscribe_keys_on_created_at (created_at)
|
|
#
|