# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2026_01_27_005300) 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
    t.bigint "record_id", null: false
    t.bigint "blob_id", null: false
    t.datetime "created_at", null: false
    t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
    t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
  end

  create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.string "key", null: false
    t.string "filename", null: false
    t.string "content_type"
    t.text "metadata"
    t.string "service_name", null: false
    t.bigint "byte_size", null: false
    t.string "checksum"
    t.datetime "created_at", null: false
    t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
  end

  create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.bigint "blob_id", null: false
    t.string "variation_digest", null: false
    t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
  end

  create_table "ip_addresses", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.binary "ip_address", limit: 16, null: false
    t.boolean "banned", default: false, null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["ip_address"], name: "index_ip_addresses_on_ip_address", unique: true
  end

  create_table "nico_tag_relations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.bigint "nico_tag_id", null: false
    t.bigint "tag_id", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["nico_tag_id"], name: "index_nico_tag_relations_on_nico_tag_id"
    t.index ["tag_id"], name: "index_nico_tag_relations_on_tag_id"
  end

  create_table "post_similarities", primary_key: ["post_id", "target_post_id"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.bigint "post_id", null: false
    t.bigint "target_post_id", null: false
    t.float "cos", null: false
    t.index ["post_id", "cos"], name: "index_post_similarities_on_post_id_and_cos", order: { cos: :desc }
    t.index ["target_post_id"], name: "index_post_similarities_on_target_post_id"
  end

  create_table "post_tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.bigint "post_id", null: false
    t.bigint "tag_id", null: false
    t.bigint "created_user_id"
    t.bigint "deleted_user_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.datetime "discarded_at"
    t.virtual "is_active", type: :boolean, as: "(`discarded_at` is null)", stored: true
    t.virtual "active_unique_key", type: :string, as: "(case when (`discarded_at` is null) then concat(`post_id`,_utf8mb4':',`tag_id`) else NULL end)", stored: true
    t.index ["active_unique_key"], name: "idx_post_tags_active_unique", unique: true
    t.index ["created_user_id"], name: "index_post_tags_on_created_user_id"
    t.index ["deleted_user_id"], name: "index_post_tags_on_deleted_user_id"
    t.index ["discarded_at"], name: "index_post_tags_on_discarded_at"
    t.index ["post_id", "discarded_at"], name: "index_post_tags_on_post_id_and_discarded_at"
    t.index ["post_id"], name: "index_post_tags_on_post_id"
    t.index ["tag_id", "discarded_at"], name: "index_post_tags_on_tag_id_and_discarded_at"
    t.index ["tag_id"], name: "index_post_tags_on_tag_id"
  end

  create_table "posts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.string "title"
    t.string "url", limit: 768, null: false
    t.string "thumbnail_base", limit: 2000
    t.bigint "parent_id"
    t.bigint "uploaded_user_id"
    t.datetime "created_at", null: false
    t.datetime "original_created_from"
    t.datetime "original_created_before"
    t.datetime "updated_at", null: false
    t.index ["parent_id"], name: "index_posts_on_parent_id"
    t.index ["uploaded_user_id"], name: "index_posts_on_uploaded_user_id"
    t.index ["url"], name: "index_posts_on_url", unique: true
  end

  create_table "settings", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.bigint "user_id", null: false
    t.string "key", null: false
    t.json "value", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["user_id"], name: "index_settings_on_user_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
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["parent_tag_id"], name: "index_tag_implications_on_parent_tag_id"
    t.index ["tag_id", "parent_tag_id"], name: "index_tag_implications_on_tag_id_and_parent_tag_id", unique: true
    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", primary_key: ["tag_id", "target_tag_id"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.bigint "tag_id", null: false
    t.bigint "target_tag_id", null: false
    t.float "cos", null: false
    t.index ["tag_id", "cos"], name: "index_tag_similarities_on_tag_id_and_cos", order: { cos: :desc }
    t.index ["target_tag_id"], name: "index_tag_similarities_on_target_tag_id"
  end

  create_table "tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    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", primary_key: ["user_id", "ip_address_id"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.bigint "user_id", null: false
    t.bigint "ip_address_id", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["ip_address_id"], name: "index_user_ips_on_ip_address_id"
  end

  create_table "user_post_views", primary_key: ["user_id", "post_id"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.bigint "user_id", null: false
    t.bigint "post_id", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["post_id"], name: "index_user_post_views_on_post_id"
  end

  create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
    t.string "name"
    t.string "inheritance_code", limit: 64, null: false
    t.string "role", null: false
    t.boolean "banned", default: false, null: false
    t.datetime "created_at", null: false
    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.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

  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"
  add_foreign_key "nico_tag_relations", "tags", column: "nico_tag_id"
  add_foreign_key "post_similarities", "posts"
  add_foreign_key "post_similarities", "posts", column: "target_post_id"
  add_foreign_key "post_tags", "posts"
  add_foreign_key "post_tags", "tags"
  add_foreign_key "post_tags", "users", column: "created_user_id"
  add_foreign_key "post_tags", "users", column: "deleted_user_id"
  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_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"
  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
