DEV: Use Single Table Inheritance in TopicTimer (#34530)

To prepare for the introduction of `CategoryDefaultTimer`, which allows
posts created in certain categories to have a default `TopicTimer`, we
first need to convert `TopicTimer` to use [Single Table
Inheritance][STI].

[STI]:
https://guides.rubyonrails.org/association_basics.html#single-table-inheritance-sti
This commit is contained in:
Linca
2025-09-01 11:13:22 +08:00
committed by GitHub
parent 86fcf37082
commit ae1fe19e63
3 changed files with 145 additions and 97 deletions
@@ -0,0 +1,12 @@
# frozen_string_literal: true
class AddTypeToTopicTimer < ActiveRecord::Migration[8.0]
def change
add_column :topic_timers, :type, :string, null: false, default: "TopicTimer"
remove_index :topic_timers, name: :idx_topic_id_public_type_deleted_at
add_index :topic_timers,
:topic_id,
unique: true,
name: :idx_topic_id_public_type_deleted_at,
where: "public_type = true AND deleted_at IS NULL AND type = 'TopicTimer'"
end
end