このコミットが含まれているのは:
@@ -237,7 +237,7 @@ class MaterialsController < ApplicationController
|
||||
end
|
||||
|
||||
def resolve_material_tag! tag_name_raw
|
||||
tag_name = TagName.find_undiscard_or_create_by!(name: tag_name_raw)
|
||||
tag_name = TagName.find_or_create_by!(name: tag_name_raw)
|
||||
tag = tag_name.tag
|
||||
tag || Tag.create!(tag_name:, category: :material)
|
||||
end
|
||||
|
||||
@@ -573,7 +573,7 @@ class TagsController < ApplicationController
|
||||
return false
|
||||
end
|
||||
|
||||
target_tag_name = TagName.with_discarded.find_by(name:)
|
||||
target_tag_name = TagName.find_by(name:)
|
||||
return true if target_tag_name.nil?
|
||||
return true if target_tag_name.canonical_id?
|
||||
|
||||
@@ -585,17 +585,14 @@ class TagsController < ApplicationController
|
||||
return if name == tag.name
|
||||
|
||||
current_tag_name = tag.tag_name
|
||||
target_tag_name = TagName.with_discarded.find_by(name:)
|
||||
target_tag_name = TagName.find_by(name:)
|
||||
|
||||
if target_tag_name.nil?
|
||||
current_tag_name.update!(name:)
|
||||
return
|
||||
end
|
||||
|
||||
promote_tag_alias!(
|
||||
tag,
|
||||
current_tag_name:,
|
||||
promoted_tag_name: target_tag_name)
|
||||
promote_tag_alias!(tag, current_tag_name:, promoted_tag_name: target_tag_name)
|
||||
end
|
||||
|
||||
def promote_tag_alias! tag, current_tag_name:, promoted_tag_name:
|
||||
@@ -605,11 +602,9 @@ class TagsController < ApplicationController
|
||||
TagVersioning.ensure_snapshot!(old_owner_tag, created_by_user: current_user)
|
||||
end
|
||||
|
||||
promoted_tag_name.undiscard! if promoted_tag_name.discarded?
|
||||
promoted_tag_name.update!(canonical: nil)
|
||||
|
||||
TagName.with_discarded
|
||||
.where(canonical_id: current_tag_name.id)
|
||||
TagName.where(canonical_id: current_tag_name.id)
|
||||
.where.not(id: promoted_tag_name.id)
|
||||
.find_each do |alias_tag_name|
|
||||
alias_tag_name.update!(canonical: promoted_tag_name)
|
||||
@@ -640,7 +635,7 @@ class TagsController < ApplicationController
|
||||
end
|
||||
|
||||
alias_names.each do |alias_name|
|
||||
alias_tag_name = TagName.find_undiscard_or_create_by!(name: alias_name)
|
||||
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
|
||||
affected_tags << alias_tag_name.canonical&.tag
|
||||
end
|
||||
|
||||
@@ -655,7 +650,7 @@ class TagsController < ApplicationController
|
||||
end
|
||||
|
||||
alias_names.each do |alias_name|
|
||||
alias_tag_name = TagName.find_undiscard_or_create_by!(name: alias_name)
|
||||
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
|
||||
alias_tag_name.update!(canonical: tag.tag_name)
|
||||
end
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class WikiPagesController < ApplicationController
|
||||
return render_unprocessable_entity('タイトルは必須です.', field: :title) if title.blank?
|
||||
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
|
||||
|
||||
tag_name = TagName.find_undiscard_or_create_by!(name: title)
|
||||
tag_name = TagName.find_or_create_by!(name: title)
|
||||
|
||||
page =
|
||||
Wiki::Commit.create_content!(
|
||||
|
||||
@@ -63,16 +63,19 @@ class Post < ApplicationRecord
|
||||
has_many :user_post_views, dependent: :delete_all
|
||||
has_many :post_similarities, dependent: :delete_all
|
||||
has_many :post_versions
|
||||
|
||||
has_many :gekanator_guessed_games,
|
||||
class_name: 'GekanatorGame',
|
||||
foreign_key: :guessed_post_id,
|
||||
dependent: :delete_all,
|
||||
inverse_of: :guessed_post
|
||||
|
||||
has_many :gekanator_correct_games,
|
||||
class_name: 'GekanatorGame',
|
||||
foreign_key: :correct_post_id,
|
||||
dependent: :delete_all,
|
||||
inverse_of: :correct_post
|
||||
|
||||
has_many :gekanator_question_examples, dependent: :delete_all
|
||||
|
||||
has_many :parent_post_implications,
|
||||
|
||||
@@ -2,8 +2,6 @@ require 'set'
|
||||
|
||||
|
||||
class Tag < ApplicationRecord
|
||||
include MyDiscard
|
||||
|
||||
class NicoTagNormalisationError < ArgumentError
|
||||
;
|
||||
end
|
||||
@@ -232,10 +230,10 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.find_or_create_by_tag_name! name, category:
|
||||
tn = TagName.find_undiscard_or_create_by!(name: name.to_s.strip)
|
||||
tn = TagName.find_or_create_by!(name: name.to_s.strip)
|
||||
tn = tn.canonical if tn.canonical_id?
|
||||
|
||||
Tag.find_undiscard_or_create_by!(tag_name_id: tn.id) do |t|
|
||||
Tag.find_or_create_by!(tag_name_id: tn.id) do |t|
|
||||
t.category = category
|
||||
end
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
@@ -273,10 +271,10 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
TagVersioning.record!(source_tag, event_type: :discard, created_by_user:)
|
||||
source_tag.discard!
|
||||
source_tag.destroy!
|
||||
|
||||
if source_tag.nico?
|
||||
source_tag_name.discard!
|
||||
source_tag_name.destroy!
|
||||
else
|
||||
source_tag_name.update_columns(canonical_id: target_tag.tag_name_id,
|
||||
updated_at: Time.current)
|
||||
@@ -297,7 +295,7 @@ class Tag < ApplicationRecord
|
||||
target_tag.reload
|
||||
end
|
||||
|
||||
def snapshot_aliases = tag_name.aliases.kept.order(:name).pluck(:name)
|
||||
def snapshot_aliases = tag_name.aliases.order(:name).pluck(:name)
|
||||
|
||||
def snapshot_parent_tag_ids = parents.order(:id).pluck(:id)
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
class TagName < ApplicationRecord
|
||||
include MyDiscard
|
||||
|
||||
has_one :tag
|
||||
has_one :wiki_page
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class TagNameSanitisationRule < ApplicationRecord
|
||||
elsif source_tag
|
||||
source_tag.update_columns(tag_name_id: existing_tn.id, updated_at: Time.current)
|
||||
end
|
||||
tn.discard!
|
||||
tn.destroy!
|
||||
|
||||
next
|
||||
end
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
class DeleteDiscardedRecordsFromTags < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
remove_foreign_key :tag_versions, :tags, column: :tag_id
|
||||
remove_foreign_key :nico_tag_versions, :tags, column: :tag_id
|
||||
remove_foreign_key :material_versions, :tags, column: :tag_id
|
||||
|
||||
execute <<~SQL
|
||||
DELETE
|
||||
ntr
|
||||
FROM
|
||||
nico_tag_relations ntr
|
||||
INNER JOIN
|
||||
tags t
|
||||
ON
|
||||
t.discarded_at IS NOT NULL
|
||||
AND t.id IN (ntr.tag_id, ntr.nico_tag_id)
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
DELETE
|
||||
ti
|
||||
FROM
|
||||
tag_implications ti
|
||||
INNER JOIN
|
||||
tags t
|
||||
ON
|
||||
t.discarded_at IS NOT NULL
|
||||
AND t.id IN (ti.tag_id, ti.parent_tag_id)
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
DELETE
|
||||
FROM
|
||||
tags
|
||||
WHERE
|
||||
discarded_at IS NOT NULL
|
||||
SQL
|
||||
|
||||
remove_index :tags, :discarded_at
|
||||
remove_column :tags, :discarded_at
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, '戻せません.'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
class DeleteDiscardedRecordsFromTagNames < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
execute <<~SQL
|
||||
DELETE
|
||||
FROM
|
||||
tag_names
|
||||
WHERE
|
||||
discarded_at IS NOT NULL
|
||||
SQL
|
||||
|
||||
remove_index :tag_names, :discarded_at
|
||||
remove_column :tag_names, :discarded_at
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, '戻せません.'
|
||||
end
|
||||
end
|
||||
生成ファイル
+1
-8
@@ -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_09_21_010000) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_09_21_030000) 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
|
||||
@@ -409,9 +409,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_09_21_010000) do
|
||||
t.bigint "canonical_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "discarded_at"
|
||||
t.index ["canonical_id"], name: "index_tag_names_on_canonical_id"
|
||||
t.index ["discarded_at"], name: "index_tag_names_on_discarded_at"
|
||||
t.index ["name"], name: "index_tag_names_on_name", unique: true
|
||||
end
|
||||
|
||||
@@ -448,10 +446,8 @@ ActiveRecord::Schema[8.0].define(version: 2026_09_21_010000) 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.integer "version_no", null: false
|
||||
t.index ["deprecated_at"], name: "index_tags_on_deprecated_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
|
||||
t.check_constraint "(`deprecated_at` is null) or (`category` <> _utf8mb4'nico')", name: "chk_tags_deprecated_at_not_nico"
|
||||
t.check_constraint "`version_no` > 0", name: "chk_tags_version_no_positive"
|
||||
@@ -698,7 +694,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_09_21_010000) do
|
||||
add_foreign_key "material_sync_suppressions", "users", column: "created_by_user_id"
|
||||
add_foreign_key "material_versions", "materials"
|
||||
add_foreign_key "material_versions", "materials", column: "parent_id"
|
||||
add_foreign_key "material_versions", "tags"
|
||||
add_foreign_key "material_versions", "users", column: "created_by_user_id"
|
||||
add_foreign_key "material_versions", "users", column: "updated_by_user_id"
|
||||
add_foreign_key "materials", "materials", column: "parent_id"
|
||||
@@ -707,7 +702,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_09_21_010000) do
|
||||
add_foreign_key "materials", "users", column: "updated_by_user_id"
|
||||
add_foreign_key "nico_tag_relations", "tags"
|
||||
add_foreign_key "nico_tag_relations", "tags", column: "nico_tag_id"
|
||||
add_foreign_key "nico_tag_versions", "tags"
|
||||
add_foreign_key "nico_tag_versions", "users", column: "created_by_user_id"
|
||||
add_foreign_key "post_implications", "posts"
|
||||
add_foreign_key "post_implications", "posts", column: "parent_post_id"
|
||||
@@ -726,7 +720,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_09_21_010000) do
|
||||
add_foreign_key "tag_names", "tag_names", column: "canonical_id"
|
||||
add_foreign_key "tag_similarities", "tags"
|
||||
add_foreign_key "tag_similarities", "tags", column: "target_tag_id"
|
||||
add_foreign_key "tag_versions", "tags"
|
||||
add_foreign_key "tag_versions", "users", column: "created_by_user_id"
|
||||
add_foreign_key "tags", "tag_names"
|
||||
add_foreign_key "theatre_comments", "theatres"
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする