1
0
Fork 0
forked from gitea/nas

Create emoji reactions table

This commit is contained in:
KMY 2023-02-23 09:14:38 +09:00
parent 87f2d18462
commit 0ebf8b302d
4 changed files with 78 additions and 1 deletions

View 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

View 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

View file

@ -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

View file

@ -10,7 +10,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.define(version: 2022_12_06_114142) do ActiveRecord::Schema.define(version: 2023_02_22_235218) 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"
@ -411,6 +411,17 @@ ActiveRecord::Schema.define(version: 2022_12_06_114142) 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"
@ -1155,6 +1166,9 @@ ActiveRecord::Schema.define(version: 2022_12_06_114142) 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