mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-21 17:30:58 +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.
67 lines
1.6 KiB
Ruby
Vendored
67 lines
1.6 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class PublishedPage < ActiveRecord::Base
|
|
belongs_to :topic
|
|
|
|
validates :slug, presence: true
|
|
validates :slug, :topic_id, uniqueness: true
|
|
|
|
validate :slug_format
|
|
def slug_format
|
|
if slug !~ /\A[a-zA-Z\-\_0-9]+\z/
|
|
errors.add(:slug, I18n.t("publish_page.slug_errors.invalid"))
|
|
elsif %w[check-slug by-topic].include?(slug)
|
|
errors.add(:slug, I18n.t("publish_page.slug_errors.unavailable"))
|
|
end
|
|
end
|
|
|
|
def path
|
|
"/pub/#{slug}"
|
|
end
|
|
|
|
def url
|
|
"#{Discourse.base_url}#{path}"
|
|
end
|
|
|
|
def self.publish!(publisher, topic, slug, options = {})
|
|
pp = nil
|
|
|
|
results =
|
|
transaction do
|
|
pp = find_or_initialize_by(topic: topic)
|
|
pp.slug = slug.strip
|
|
pp.public = options[:public] || false
|
|
|
|
if pp.save
|
|
StaffActionLogger.new(publisher).log_published_page(topic.id, slug)
|
|
[true, pp]
|
|
end
|
|
end
|
|
|
|
results || [false, pp]
|
|
end
|
|
|
|
def self.unpublish!(publisher, topic)
|
|
if pp = PublishedPage.find_by(topic_id: topic.id)
|
|
pp.destroy!
|
|
StaffActionLogger.new(publisher).log_unpublished_page(topic.id, pp.slug)
|
|
end
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: published_pages
|
|
#
|
|
# id :bigint not null, primary key
|
|
# public :boolean default(FALSE), not null
|
|
# slug :string not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# topic_id :bigint not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_published_pages_on_slug (slug) UNIQUE
|
|
# index_published_pages_on_topic_id (topic_id) UNIQUE
|
|
#
|