Browse Source

#287

feature/287
みてるぞ 2 weeks ago
parent
commit
5e28159326
3 changed files with 24 additions and 2 deletions
  1. +5
    -1
      backend/app/models/tag.rb
  2. +6
    -0
      backend/db/migrate/20260311123100_add_discarded_at_to_tags.rb
  3. +13
    -1
      backend/db/schema.rb

+ 5
- 1
backend/app/models/tag.rb View File

@@ -1,8 +1,12 @@
class Tag < ApplicationRecord
include Discard::Model

class NicoTagNormalisationError < ArgumentError
;
end

default_scope -> { kept }

has_many :post_tags, inverse_of: :tag
has_many :active_post_tags, -> { kept }, class_name: 'PostTag', inverse_of: :tag
has_many :post_tags_with_discarded, -> { with_discarded }, class_name: 'PostTag'
@@ -160,7 +164,7 @@ class Tag < ApplicationRecord
end

tag_name = st.tag_name
st.destroy!
st.discard!
tag_name.reload
tag_name.update!(canonical: target_tag.tag_name)
end


+ 6
- 0
backend/db/migrate/20260311123100_add_discarded_at_to_tags.rb View File

@@ -0,0 +1,6 @@
class AddDiscardedAtToTags < ActiveRecord::Migration[8.0]
def change
add_column :tags, :discarded_at, :datetime
add_index :tags, :discarded_at
end
end

+ 13
- 1
backend/db/schema.rb View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2026_03_03_122700) do
ActiveRecord::Schema[8.0].define(version: 2026_03_11_123100) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
@@ -127,6 +127,16 @@ ActiveRecord::Schema[8.0].define(version: 2026_03_03_122700) do
t.index ["tag_id"], name: "index_tag_implications_on_tag_id"
end

create_table "tag_name_sanitisation_rules", primary_key: "priority", id: :integer, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "source_pattern", null: false
t.string "replacement", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "discarded_at"
t.index ["discarded_at"], name: "index_tag_name_sanitisation_rules_on_discarded_at"
t.index ["source_pattern"], name: "index_tag_name_sanitisation_rules_on_source_pattern", unique: true
end

create_table "tag_names", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false
t.bigint "canonical_id"
@@ -150,6 +160,8 @@ ActiveRecord::Schema[8.0].define(version: 2026_03_03_122700) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "post_count", default: 0, null: false
t.datetime "discarded_at"
t.index ["discarded_at"], name: "index_tags_on_discarded_at"
t.index ["tag_name_id"], name: "index_tags_on_tag_name_id", unique: true
end



Loading…
Cancel
Save