class AddSettingsToAccounts < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def change
add_column :accounts, :settings, :jsonb, null: false, default: {}
class AddSearchVectorToArticles < ActiveRecord::Migration[7.1]
def up
execute <<~SQL
ALTER TABLE articles
ADD COLUMN search_vector tsvector
GENERATED ALWAYS AS (
class AttachmentContentTypeValidator < ActiveModel::EachValidator
SIGNATURES = {
"image/png" => ["\x89PNG\r\n\x1a\n".b],
"image/jpeg" => ["\xFF\xD8\xFF".b],
"image/gif" => ["GIF87a".b, "GIF89a".b],
"application/pdf" => ["%PDF-".b]
module EmailNormalization
extend ActiveSupport::Concern
included do
attr_accessor :soft_warnings
module QueryBudget
class Counter
IGNORED = %w[SCHEMA CACHE TRANSACTION].freeze
attr_reader :count
class SlidingWindowLimiter
Result = Struct.new(:allowed, :count, :limit, :window_ms, keyword_init: true)
SCRIPT = <<~LUA.freeze
local key = KEYS[1]
local now = tonumber(ARGV[1])
class CreateSubscriptions < ActiveRecord::Migration[7.1]
STATUSES = %w[pending active past_due canceled].freeze
def change
create_table :subscriptions do |t|
t.references :account, null: false, foreign_key: true
class LeaderboardCache
TOP_KEY = "leaderboard:top".freeze
STATS_KEY = "leaderboard:stats".freeze
def top_players
Rails.cache.fetch(TOP_KEY, expires_in: 5.minutes, race_condition_ttl: 15.seconds) do
module ConditionalGet
extend ActiveSupport::Concern
private
def render_conditional(resource, extra: nil)
class Document < ApplicationRecord
belongs_to :owner, class_name: "User"
has_many :visibilities, class_name: "DocumentVisibility", dependent: :delete_all
scope :public_documents, -> { where(is_public: true) }
class Order < ApplicationRecord
include TransactionalEnqueue
belongs_to :customer
has_many :line_items, dependent: :destroy
class Post < ApplicationRecord
has_many :comments, dependent: :destroy
# comments_count is maintained by counter_cache on Comment#belongs_to
scope :stale_comment_counts, lambda {