Add TaggedObject model

This commit is contained in:
Claire 2026-03-09 15:31:02 +01:00
parent 1ee457f2d3
commit ea9ae22833
5 changed files with 60 additions and 1 deletions

View File

@ -80,6 +80,7 @@ class Status < ApplicationRecord
has_many :mentions, dependent: :destroy, inverse_of: :status
has_many :mentioned_accounts, through: :mentions, source: :account, class_name: 'Account'
has_many :media_attachments, dependent: :nullify
has_many :tagged_objects, dependent: :destroy
has_many :quotes, foreign_key: 'quoted_status_id', inverse_of: :quoted_status, dependent: :nullify
# The `dependent` option is enabled by the initial `mentions` association declaration

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: tagged_objects
#
# id :bigint(8) not null, primary key
# ap_type :string not null
# object_type :string
# uri :string
# created_at :datetime not null
# updated_at :datetime not null
# object_id :bigint(8)
# status_id :bigint(8) not null
#
class TaggedObject < ApplicationRecord
belongs_to :status, inverse_of: :tagged_objects
belongs_to :object, polymorphic: true, optional: true
end

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
class CreateTaggedObjects < ActiveRecord::Migration[8.1]
def change
create_table :tagged_objects do |t|
t.references :status, null: false, foreign_key: { on_delete: :cascade }, index: false
t.references :object, polymorphic: true, null: true
t.string :ap_type, null: false
t.string :uri
t.timestamps
end
add_index :tagged_objects, [:status_id, :object_type, :object_id], unique: true, where: 'object_type IS NOT NULL AND object_id IS NOT NULL'
add_index :tagged_objects, [:status_id, :uri], unique: true, where: 'uri IS NOT NULL'
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_03_18_144837) do
ActiveRecord::Schema[8.1].define(version: 2026_03_19_142348) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@ -1242,6 +1242,19 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_18_144837) do
t.index ["tag_id", "language"], name: "index_tag_trends_on_tag_id_and_language", unique: true
end
create_table "tagged_objects", force: :cascade do |t|
t.string "ap_type", null: false
t.datetime "created_at", null: false
t.bigint "object_id"
t.string "object_type"
t.bigint "status_id", null: false
t.datetime "updated_at", null: false
t.string "uri"
t.index ["object_type", "object_id"], name: "index_tagged_objects_on_object"
t.index ["status_id", "object_type", "object_id"], name: "idx_on_status_id_object_type_object_id_d6ebe374bd", unique: true, where: "((object_type IS NOT NULL) AND (object_id IS NOT NULL))"
t.index ["status_id", "uri"], name: "index_tagged_objects_on_status_id_and_uri", unique: true, where: "(uri IS NOT NULL)"
end
create_table "tags", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.string "display_name"
@ -1547,6 +1560,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_18_144837) do
add_foreign_key "tag_follows", "accounts", on_delete: :cascade
add_foreign_key "tag_follows", "tags", on_delete: :cascade
add_foreign_key "tag_trends", "tags", on_delete: :cascade
add_foreign_key "tagged_objects", "statuses", on_delete: :cascade
add_foreign_key "tombstones", "accounts", on_delete: :cascade
add_foreign_key "user_invite_requests", "users", on_delete: :cascade
add_foreign_key "users", "accounts", name: "fk_50500f500d", on_delete: :cascade

View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
Fabricator(:tagged_object) do
status
object nil
ap_type 'FeaturedCollection'
uri { Faker::Internet.device_token }
end