mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-26 17:48:30 +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.
53 lines
1.4 KiB
Ruby
Vendored
53 lines
1.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class GivenDailyLike < ActiveRecord::Base
|
|
belongs_to :user
|
|
|
|
def self.find_for(user_id, date)
|
|
where(user_id: user_id, given_date: date)
|
|
end
|
|
|
|
def self.increment_for(user_id)
|
|
return unless user_id
|
|
given_date = Date.today
|
|
|
|
# upsert would be nice here
|
|
rows = find_for(user_id, given_date).update_all("likes_given = likes_given + 1")
|
|
|
|
if rows == 0
|
|
create(user_id: user_id, given_date: given_date, likes_given: 1)
|
|
else
|
|
find_for(user_id, given_date).where(
|
|
"limit_reached = false AND likes_given >= :limit",
|
|
limit: SiteSetting.max_likes_per_day,
|
|
).update_all(limit_reached: true)
|
|
end
|
|
end
|
|
|
|
def self.decrement_for(user_id)
|
|
return unless user_id
|
|
|
|
given_date = Date.today
|
|
|
|
find_for(user_id, given_date).update_all("likes_given = likes_given - 1")
|
|
find_for(user_id, given_date).where(
|
|
"limit_reached = true AND likes_given < :limit",
|
|
limit: SiteSetting.max_likes_per_day,
|
|
).update_all(limit_reached: false)
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: given_daily_likes
|
|
#
|
|
# given_date :date not null
|
|
# likes_given :integer not null
|
|
# limit_reached :boolean default(FALSE), not null
|
|
# user_id :integer not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_given_daily_likes_on_limit_reached_and_user_id (limit_reached,user_id)
|
|
# index_given_daily_likes_on_user_id_and_given_date (user_id,given_date) UNIQUE
|
|
#
|