feat: タグ名を別管理に変更(#215) (#219)
Merge branch 'main' into feature/215 #215 ニコニコ同期テスト #215 テスト・ケース追加 #215 テスト・ケース追加 #215 テスト・ケース追加 #215 テスト・ケース追加 Merge remote-tracking branch 'origin/main' into feature/215 Merge branch 'main' into feature/215 #215 #215 Merge remote-tracking branch 'origin/main' into feature/215 #215 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #219
This commit was merged in pull request #219.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
class CreateTagNames < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :tag_names do |t|
|
||||
t.string :name, limit: 255, null: false
|
||||
t.references :canonical, null: true, foreign_key: { to_table: :tag_names }, index: true
|
||||
t.timestamps
|
||||
end
|
||||
add_index :tag_names, :name, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,42 @@
|
||||
class AddTagNameToTags < ActiveRecord::Migration[7.0]
|
||||
class Tag < ApplicationRecord
|
||||
self.table_name = 'tags'
|
||||
end
|
||||
|
||||
class TagName < ApplicationRecord
|
||||
self.table_name = 'tag_names'
|
||||
end
|
||||
|
||||
def up
|
||||
add_reference :tags, :tag_name, null: true, foreign_key: true, index: false, after: :id
|
||||
add_index :tags, :tag_name_id, unique: true
|
||||
|
||||
Tag.find_each do |tag|
|
||||
name = tag.read_attribute(:name)
|
||||
tn = TagName.find_or_create_by!(name:) do |r|
|
||||
r.canonical_id = nil
|
||||
end
|
||||
tag.update_columns(tag_name_id: tn.id)
|
||||
end
|
||||
|
||||
change_column_null :tags, :tag_name_id, false
|
||||
|
||||
remove_column :tags, :name
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :tags, :name, :string, limit: 255, null: true, after: :id
|
||||
|
||||
Tag.find_each do |tag|
|
||||
tag_name_id = tag.read_attribute(:tag_name_id)
|
||||
name = TagName.find(tag_name_id).read_attribute(:name)
|
||||
tag.update_columns(name:)
|
||||
end
|
||||
|
||||
change_column_null :tags, :name, false
|
||||
|
||||
remove_foreign_key :tags, column: :tag_name_id
|
||||
remove_index :tags, :tag_name_id
|
||||
remove_column :tags, :tag_name_id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,42 @@
|
||||
class AddTagNameToWikiPages < ActiveRecord::Migration[7.0]
|
||||
class WikiPage < ApplicationRecord
|
||||
self.table_name = 'wiki_pages'
|
||||
end
|
||||
|
||||
class TagName < ApplicationRecord
|
||||
self.table_name = 'tag_names'
|
||||
end
|
||||
|
||||
def up
|
||||
add_reference :wiki_pages, :tag_name, null: true, foreign_key: true, index: false, after: :id
|
||||
add_index :wiki_pages, :tag_name_id, unique: true
|
||||
|
||||
WikiPage.find_each do |page|
|
||||
name = page.read_attribute(:title)
|
||||
tn = TagName.find_or_create_by!(name:) do |r|
|
||||
r.canonical_id = nil
|
||||
end
|
||||
page.update_columns(tag_name_id: tn.id)
|
||||
end
|
||||
|
||||
change_column_null :wiki_pages, :tag_name_id, false
|
||||
|
||||
remove_column :wiki_pages, :title
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :wiki_pages, :title, :string, limit: 255, null: true, after: :id
|
||||
|
||||
WikiPage.find_each do |page|
|
||||
tag_name_id = page.read_attribute(:tag_name_id)
|
||||
title = TagName.find(tag_name_id).read_attribute(:name)
|
||||
page.update_columns(title:)
|
||||
end
|
||||
|
||||
change_column_null :wiki_pages, :title, false
|
||||
|
||||
remove_foreign_key :wiki_pages, column: :tag_name_id
|
||||
remove_index :wiki_pages, :tag_name_id
|
||||
remove_column :wiki_pages, :tag_name_id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class DropTagAliases < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
drop_table :tag_aliases
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, '戻せません.'
|
||||
end
|
||||
end
|
||||
Generated
+17
-12
@@ -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_01_07_034300) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_01_12_111800) 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
|
||||
@@ -106,14 +106,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_07_034300) do
|
||||
t.index ["user_id"], name: "index_settings_on_user_id"
|
||||
end
|
||||
|
||||
create_table "tag_aliases", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
t.bigint "tag_id", null: false
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["tag_id"], name: "index_tag_aliases_on_tag_id"
|
||||
end
|
||||
|
||||
create_table "tag_implications", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
t.bigint "tag_id", null: false
|
||||
t.bigint "parent_tag_id", null: false
|
||||
@@ -124,6 +116,15 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_07_034300) do
|
||||
t.index ["tag_id"], name: "index_tag_implications_on_tag_id"
|
||||
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"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["canonical_id"], name: "index_tag_names_on_canonical_id"
|
||||
t.index ["name"], name: "index_tag_names_on_name", unique: true
|
||||
end
|
||||
|
||||
create_table "tag_similarities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
t.bigint "tag_id", null: false
|
||||
t.bigint "target_tag_id", null: false
|
||||
@@ -133,11 +134,12 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_07_034300) do
|
||||
end
|
||||
|
||||
create_table "tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.bigint "tag_name_id", null: false
|
||||
t.string "category", default: "general", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "post_count", default: 0, null: false
|
||||
t.index ["tag_name_id"], name: "index_tags_on_tag_name_id", unique: true
|
||||
end
|
||||
|
||||
create_table "user_ips", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
@@ -176,12 +178,13 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_07_034300) do
|
||||
end
|
||||
|
||||
create_table "wiki_pages", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
t.string "title", null: false
|
||||
t.bigint "tag_name_id", null: false
|
||||
t.bigint "created_user_id", null: false
|
||||
t.bigint "updated_user_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["created_user_id"], name: "index_wiki_pages_on_created_user_id"
|
||||
t.index ["tag_name_id"], name: "index_wiki_pages_on_tag_name_id", unique: true
|
||||
t.index ["updated_user_id"], name: "index_wiki_pages_on_updated_user_id"
|
||||
end
|
||||
|
||||
@@ -228,15 +231,17 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_07_034300) do
|
||||
add_foreign_key "posts", "posts", column: "parent_id"
|
||||
add_foreign_key "posts", "users", column: "uploaded_user_id"
|
||||
add_foreign_key "settings", "users"
|
||||
add_foreign_key "tag_aliases", "tags"
|
||||
add_foreign_key "tag_implications", "tags"
|
||||
add_foreign_key "tag_implications", "tags", column: "parent_tag_id"
|
||||
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 "tags", "tag_names"
|
||||
add_foreign_key "user_ips", "ip_addresses"
|
||||
add_foreign_key "user_ips", "users"
|
||||
add_foreign_key "user_post_views", "posts"
|
||||
add_foreign_key "user_post_views", "users"
|
||||
add_foreign_key "wiki_pages", "tag_names"
|
||||
add_foreign_key "wiki_pages", "users", column: "created_user_id"
|
||||
add_foreign_key "wiki_pages", "users", column: "updated_user_id"
|
||||
add_foreign_key "wiki_revision_lines", "wiki_lines"
|
||||
|
||||
Reference in New Issue
Block a user