diff --git a/backend/db/migrate/20251229012100_remove_tag_from_wiki_pages.rb b/backend/db/migrate/20251229012100_remove_tag_from_wiki_pages.rb new file mode 100644 index 0000000..f4ef842 --- /dev/null +++ b/backend/db/migrate/20251229012100_remove_tag_from_wiki_pages.rb @@ -0,0 +1,5 @@ +class RemoveTagFromWikiPages < ActiveRecord::Migration[7.0] + def change + remove_reference :wiki_pages, :tag, if_exists: true + end +end diff --git a/backend/db/migrate/20251229020700_create_wiki_lines.rb b/backend/db/migrate/20251229020700_create_wiki_lines.rb new file mode 100644 index 0000000..cba6fb4 --- /dev/null +++ b/backend/db/migrate/20251229020700_create_wiki_lines.rb @@ -0,0 +1,11 @@ +class CreateWikiLines < ActiveRecord::Migration[7.0] + def change + create_table :wiki_lines do |t| + t.string :sha256, null: false, limit: 64 + t.text :body, null: false + t.timestamps + end + + add_index :wiki_lines, :sha256, unique: true + end +end diff --git a/backend/db/migrate/20251229021000_create_wiki_revisions.rb b/backend/db/migrate/20251229021000_create_wiki_revisions.rb new file mode 100644 index 0000000..5b80621 --- /dev/null +++ b/backend/db/migrate/20251229021000_create_wiki_revisions.rb @@ -0,0 +1,19 @@ +class CreateWikiRevisions < ActiveRecord::Migration[7.0] + def change + create_table :wiki_revisions do |t| + t.references :wiki_page, null: false, foreign_key: true + t.references :base_revision, foreign_key: { to_table: :wiki_revisions } + t.references :created_user, null: false, foreign_key: { to_table: :users } + t.integer :kind, null: false, default: 0 # 0: content, 1: redirect + t.references :redirect_page, foreign_key: { to_table: :wiki_pages } + t.string :message + t.integer :lines_count, null: false, default: 0 + t.string :tree_sha256, limit: 64 + t.timestamps + end + + add_index :wiki_revisions, :tree_sha256 + add_index :wiki_revisions, [:wiki_page_id, :id] + add_index :wiki_revisions, :kind + end +end diff --git a/backend/db/migrate/20251229022100_create_wiki_revision_lines.rb b/backend/db/migrate/20251229022100_create_wiki_revision_lines.rb new file mode 100644 index 0000000..e62a7c4 --- /dev/null +++ b/backend/db/migrate/20251229022100_create_wiki_revision_lines.rb @@ -0,0 +1,12 @@ +class CreateWikiRevisionLines < ActiveRecord::Migration[7.0] + def change + create_table :wiki_revision_lines do |t| + t.references :wiki_revision, null: false, foreign_key: true + t.integer :position, null: false + t.references :wiki_line, null: false, foreign_key: true + end + + add_index :wiki_revision_lines, [:wiki_revision_id, :position], unique: true + add_index :wiki_revision_lines, [:wiki_revision_id, :wiki_line_id] + end +end diff --git a/backend/db/schema.rb b/backend/db/schema.rb index 6a26dfd..116a1a2 100644 --- a/backend/db/schema.rb +++ b/backend/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_12_10_123200) do +ActiveRecord::Schema[8.0].define(version: 2025_12_29_022100) 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 @@ -167,18 +167,54 @@ ActiveRecord::Schema[8.0].define(version: 2025_12_10_123200) do t.datetime "updated_at", null: false end + create_table "wiki_lines", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "sha256", limit: 64, null: false + t.text "body", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["sha256"], name: "index_wiki_lines_on_sha256", unique: true + end + create_table "wiki_pages", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "title", null: false - t.bigint "tag_id" 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_id"], name: "index_wiki_pages_on_tag_id" t.index ["updated_user_id"], name: "index_wiki_pages_on_updated_user_id" end + create_table "wiki_revision_lines", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.bigint "wiki_revision_id", null: false + t.integer "position", null: false + t.bigint "wiki_line_id", null: false + t.index ["wiki_line_id"], name: "index_wiki_revision_lines_on_wiki_line_id" + t.index ["wiki_revision_id", "position"], name: "index_wiki_revision_lines_on_wiki_revision_id_and_position", unique: true + t.index ["wiki_revision_id", "wiki_line_id"], name: "index_wiki_revision_lines_on_wiki_revision_id_and_wiki_line_id" + t.index ["wiki_revision_id"], name: "index_wiki_revision_lines_on_wiki_revision_id" + end + + create_table "wiki_revisions", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.bigint "wiki_page_id", null: false + t.bigint "base_revision_id" + t.bigint "created_user_id", null: false + t.integer "kind", default: 0, null: false + t.bigint "redirect_page_id" + t.string "message" + t.integer "lines_count", default: 0, null: false + t.string "tree_sha256", limit: 64 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["base_revision_id"], name: "index_wiki_revisions_on_base_revision_id" + t.index ["created_user_id"], name: "index_wiki_revisions_on_created_user_id" + t.index ["kind"], name: "index_wiki_revisions_on_kind" + t.index ["redirect_page_id"], name: "index_wiki_revisions_on_redirect_page_id" + t.index ["tree_sha256"], name: "index_wiki_revisions_on_tree_sha256" + t.index ["wiki_page_id", "id"], name: "index_wiki_revisions_on_wiki_page_id_and_id" + t.index ["wiki_page_id"], name: "index_wiki_revisions_on_wiki_page_id" + end + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "nico_tag_relations", "tags" @@ -201,7 +237,12 @@ ActiveRecord::Schema[8.0].define(version: 2025_12_10_123200) do 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", "tags" 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" + add_foreign_key "wiki_revision_lines", "wiki_revisions" + add_foreign_key "wiki_revisions", "users", column: "created_user_id" + add_foreign_key "wiki_revisions", "wiki_pages" + add_foreign_key "wiki_revisions", "wiki_pages", column: "redirect_page_id" + add_foreign_key "wiki_revisions", "wiki_revisions", column: "base_revision_id" end