Create emoji reactions table
This commit is contained in:
parent
e443f3c90a
commit
b88e3942cc
44
app/models/emoji_reaction.rb
Normal file
44
app/models/emoji_reaction.rb
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: emoji_reactions
|
||||||
|
#
|
||||||
|
# id :bigint(8) not null, primary key
|
||||||
|
# account_id :bigint(8) not null
|
||||||
|
# status_id :bigint(8) not null
|
||||||
|
# name :string default(""), not null
|
||||||
|
# custom_emoji_id :bigint(8)
|
||||||
|
# uri :string
|
||||||
|
# created_at :datetime
|
||||||
|
# updated_at :datetime
|
||||||
|
#
|
||||||
|
|
||||||
|
class EmojiReaction < ApplicationRecord
|
||||||
|
include Paginable
|
||||||
|
|
||||||
|
update_index('statuses', :status)
|
||||||
|
|
||||||
|
belongs_to :account, inverse_of: :emoji_reactions
|
||||||
|
belongs_to :status, inverse_of: :emoji_reactions
|
||||||
|
belongs_to :custom_emojis, optional: true
|
||||||
|
|
||||||
|
has_one :notification, as: :activity, dependent: :destroy
|
||||||
|
|
||||||
|
validates :status_id, uniqueness: { scope: :account_id }
|
||||||
|
|
||||||
|
before_validation do
|
||||||
|
self.status = status.reblog if status&.reblog?
|
||||||
|
end
|
||||||
|
|
||||||
|
after_destroy :invalidate_cleanup_info
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def invalidate_cleanup_info
|
||||||
|
return unless status&.account_id == account_id && account.local?
|
||||||
|
|
||||||
|
account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unfav)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
13
db/migrate/20230222232121_create_emoji_reactions.rb
Normal file
13
db/migrate/20230222232121_create_emoji_reactions.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class CreateEmojiReactions < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
create_table :emoji_reactions do |t|
|
||||||
|
|
||||||
|
t.belongs_to :account, null: false, foreign_key: { on_delete: :cascade }, index: false
|
||||||
|
t.belongs_to :status, null: false, foreign_key: { on_delete: :cascade }
|
||||||
|
t.string :name, null: false, default: ''
|
||||||
|
t.belongs_to :custom_emoji, foreign_key: { on_delete: :cascade }, index: false
|
||||||
|
t.string :uri
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,6 @@
|
|||||||
|
class AddCreateAtToEmojiReactions < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :emoji_reactions, :created_at, :timestamp
|
||||||
|
add_column :emoji_reactions, :updated_at, :timestamp
|
||||||
|
end
|
||||||
|
end
|
15
db/schema.rb
15
db/schema.rb
@ -11,6 +11,7 @@
|
|||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2023_12_12_073317) do
|
ActiveRecord::Schema[7.1].define(version: 2023_12_12_073317) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@ -438,6 +439,17 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_12_073317) do
|
|||||||
t.index ["domain"], name: "index_email_domain_blocks_on_domain", unique: true
|
t.index ["domain"], name: "index_email_domain_blocks_on_domain", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "emoji_reactions", force: :cascade do |t|
|
||||||
|
t.bigint "account_id", null: false
|
||||||
|
t.bigint "status_id", null: false
|
||||||
|
t.string "name", default: "", null: false
|
||||||
|
t.bigint "custom_emoji_id"
|
||||||
|
t.string "uri"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
t.index ["status_id"], name: "index_emoji_reactions_on_status_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "encrypted_messages", id: :bigint, default: -> { "timestamp_id('encrypted_messages'::text)" }, force: :cascade do |t|
|
create_table "encrypted_messages", id: :bigint, default: -> { "timestamp_id('encrypted_messages'::text)" }, force: :cascade do |t|
|
||||||
t.bigint "device_id"
|
t.bigint "device_id"
|
||||||
t.bigint "from_account_id"
|
t.bigint "from_account_id"
|
||||||
@ -1214,6 +1226,9 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_12_073317) do
|
|||||||
add_foreign_key "devices", "accounts", on_delete: :cascade
|
add_foreign_key "devices", "accounts", on_delete: :cascade
|
||||||
add_foreign_key "devices", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade
|
add_foreign_key "devices", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade
|
||||||
add_foreign_key "email_domain_blocks", "email_domain_blocks", column: "parent_id", on_delete: :cascade
|
add_foreign_key "email_domain_blocks", "email_domain_blocks", column: "parent_id", on_delete: :cascade
|
||||||
|
add_foreign_key "emoji_reactions", "accounts", on_delete: :cascade
|
||||||
|
add_foreign_key "emoji_reactions", "custom_emojis", on_delete: :cascade
|
||||||
|
add_foreign_key "emoji_reactions", "statuses", on_delete: :cascade
|
||||||
add_foreign_key "encrypted_messages", "accounts", column: "from_account_id", on_delete: :cascade
|
add_foreign_key "encrypted_messages", "accounts", column: "from_account_id", on_delete: :cascade
|
||||||
add_foreign_key "encrypted_messages", "devices", on_delete: :cascade
|
add_foreign_key "encrypted_messages", "devices", on_delete: :cascade
|
||||||
add_foreign_key "favourites", "accounts", name: "fk_5eb6c2b873", on_delete: :cascade
|
add_foreign_key "favourites", "accounts", name: "fk_5eb6c2b873", on_delete: :cascade
|
||||||
|
Loading…
Reference in New Issue
Block a user