@@ -0,0 +1,6 @@ | |||||
class IpAddress < ApplicationRecord | |||||
validates :ip_address, presence: true, length: { maximum: 16 } | |||||
validates :banned, inclusion: { in: [true, false] } | |||||
has_many :users | |||||
end |
@@ -0,0 +1,17 @@ | |||||
class NicoTagRelation < ApplicationRecord | |||||
belongs_to :nico_tag, class_name: 'Tag', foreign_key: 'nico_tag_id' | |||||
belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id' | |||||
validates :nico_tag_id, presence: true | |||||
validates :tag_id, prosence: true | |||||
validate :nico_tag_must_be_nico | |||||
private | |||||
def nico_tag_must_be_nico | |||||
if nico_tag && nico_tag.category != :nico | |||||
errors.add :nico_tag_id, 'タグのカテゴリがニコニコである必要があります.' | |||||
end | |||||
end | |||||
end |
@@ -1,2 +1,4 @@ | |||||
class Post < ApplicationRecord | class Post < ApplicationRecord | ||||
belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id' | |||||
belongs_to :user, foreign_key: '' | |||||
end | end |
@@ -0,0 +1,14 @@ | |||||
class Tag < ApplicationRecord | |||||
validates :name, presence: true, length: { maximum: 255 } | |||||
validates :category, presence: true, inclusion: { in: categories.keys } | |||||
enum category: { deerjikist: 'deerjikist', | |||||
meme: 'meme', | |||||
character: 'character', | |||||
general: 'general', | |||||
material: 'material', | |||||
nico: 'nico', | |||||
meta: 'meta' } | |||||
scope :nico_tags, -> { where(category: :nico) } | |||||
end |
@@ -0,0 +1,12 @@ | |||||
class User < ApplicationRecord | |||||
validates :name, length: { maximum: 255 } | |||||
validates :inheritance_code, presence: true, length: { maximum: 64 } | |||||
validates :role, presence: true, inclusion: { in: roles.keys } | |||||
validates :banned, inclusion: { in: [true, false] } | |||||
enum role: { guest: 'guest', member: 'member', admin: 'admin' } | |||||
has_many :posts | |||||
has_many :settings | |||||
has_many :ip_addresses | |||||
end |
@@ -4,8 +4,8 @@ class CreatePosts < ActiveRecord::Migration[7.0] | |||||
t.string :url, limit: 2000, null: false | t.string :url, limit: 2000, null: false | ||||
t.string :thumbnail, limit: 255, null: false | t.string :thumbnail, limit: 255, null: false | ||||
t.string :thumbnail_base, limit: 2000, null: false | t.string :thumbnail_base, limit: 2000, null: false | ||||
t.references :post, foreign_key: { to_table: :posts } | |||||
t.references :uploaded_by, foreign_key: { to_table: :users } | |||||
t.references :parent, foreign_key: { to_table: :posts } | |||||
t.references :uploaded_user, foreign_key: { to_table: :users } | |||||
t.timestamps | t.timestamps | ||||
end | end | ||||
end | end | ||||
@@ -3,8 +3,8 @@ class CreatePostTags < ActiveRecord::Migration[7.0] | |||||
create_table :post_tags do |t| | create_table :post_tags do |t| | ||||
t.references :post, null: false, foreign_key: { to_table: :posts } | t.references :post, null: false, foreign_key: { to_table: :posts } | ||||
t.references :tag, null: false, foreign_key: { to_table: :tags } | t.references :tag, null: false, foreign_key: { to_table: :tags } | ||||
t.references :created_by, foreign_key: { to_table: :users } | |||||
t.references :deleted_by, foreign_key: { to_table: :users } | |||||
t.references :created_user, foreign_key: { to_table: :users } | |||||
t.references :deleted_user, foreign_key: { to_table: :users } | |||||
t.timestamps | t.timestamps | ||||
end | end | ||||
end | end | ||||
@@ -3,8 +3,8 @@ class CreateWikiPages < ActiveRecord::Migration[7.0] | |||||
create_table :wiki_pages do |t| | create_table :wiki_pages do |t| | ||||
t.string :title, limit: 255, null: false | t.string :title, limit: 255, null: false | ||||
t.references :tag, foreign_key: { to_table: :tags } | t.references :tag, foreign_key: { to_table: :tags } | ||||
t.references :created_by, null: false, foreign_key: { to_table: :users } | |||||
t.references :updated_by, null: false, foreign_key: { to_table: :users } | |||||
t.references :created_user, null: false, foreign_key: { to_table: :users } | |||||
t.references :updated_user, null: false, foreign_key: { to_table: :users } | |||||
t.timestamps | t.timestamps | ||||
end | end | ||||
end | end | ||||
@@ -30,12 +30,12 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_27_214100) do | |||||
create_table "post_tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| | create_table "post_tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| | ||||
t.bigint "post_id", null: false | t.bigint "post_id", null: false | ||||
t.bigint "tag_id", null: false | t.bigint "tag_id", null: false | ||||
t.bigint "created_by_id" | |||||
t.bigint "deleted_by_id" | |||||
t.bigint "created_user_id" | |||||
t.bigint "deleted_user_id" | |||||
t.datetime "created_at", null: false | t.datetime "created_at", null: false | ||||
t.datetime "updated_at", null: false | t.datetime "updated_at", null: false | ||||
t.index ["created_by_id"], name: "index_post_tags_on_created_by_id" | |||||
t.index ["deleted_by_id"], name: "index_post_tags_on_deleted_by_id" | |||||
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 ["post_id"], name: "index_post_tags_on_post_id" | t.index ["post_id"], name: "index_post_tags_on_post_id" | ||||
t.index ["tag_id"], name: "index_post_tags_on_tag_id" | t.index ["tag_id"], name: "index_post_tags_on_tag_id" | ||||
end | end | ||||
@@ -44,12 +44,12 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_27_214100) do | |||||
t.string "url", limit: 2000, null: false | t.string "url", limit: 2000, null: false | ||||
t.string "thumbnail", null: false | t.string "thumbnail", null: false | ||||
t.string "thumbnail_base", limit: 2000, null: false | t.string "thumbnail_base", limit: 2000, null: false | ||||
t.bigint "post_id" | |||||
t.bigint "uploaded_by_id" | |||||
t.bigint "parent_id" | |||||
t.bigint "uploaded_user_id" | |||||
t.datetime "created_at", null: false | t.datetime "created_at", null: false | ||||
t.datetime "updated_at", null: false | t.datetime "updated_at", null: false | ||||
t.index ["post_id"], name: "index_posts_on_post_id" | |||||
t.index ["uploaded_by_id"], name: "index_posts_on_uploaded_by_id" | |||||
t.index ["parent_id"], name: "index_posts_on_parent_id" | |||||
t.index ["uploaded_user_id"], name: "index_posts_on_uploaded_user_id" | |||||
end | end | ||||
create_table "settings", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| | create_table "settings", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| | ||||
@@ -107,23 +107,23 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_27_214100) do | |||||
create_table "wiki_pages", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| | create_table "wiki_pages", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| | ||||
t.string "title", null: false | t.string "title", null: false | ||||
t.bigint "tag_id" | t.bigint "tag_id" | ||||
t.bigint "created_by_id", null: false | |||||
t.bigint "updated_by_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 "created_at", null: false | ||||
t.datetime "updated_at", null: false | t.datetime "updated_at", null: false | ||||
t.index ["created_by_id"], name: "index_wiki_pages_on_created_by_id" | |||||
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 ["tag_id"], name: "index_wiki_pages_on_tag_id" | ||||
t.index ["updated_by_id"], name: "index_wiki_pages_on_updated_by_id" | |||||
t.index ["updated_user_id"], name: "index_wiki_pages_on_updated_user_id" | |||||
end | end | ||||
add_foreign_key "nico_tag_relations", "tags" | add_foreign_key "nico_tag_relations", "tags" | ||||
add_foreign_key "nico_tag_relations", "tags", column: "nico_tag_id" | add_foreign_key "nico_tag_relations", "tags", column: "nico_tag_id" | ||||
add_foreign_key "post_tags", "posts" | add_foreign_key "post_tags", "posts" | ||||
add_foreign_key "post_tags", "tags" | add_foreign_key "post_tags", "tags" | ||||
add_foreign_key "post_tags", "users", column: "created_by_id" | |||||
add_foreign_key "post_tags", "users", column: "deleted_by_id" | |||||
add_foreign_key "posts", "posts" | |||||
add_foreign_key "posts", "users", column: "uploaded_by_id" | |||||
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 "settings", "users" | ||||
add_foreign_key "tag_aliases", "tags" | add_foreign_key "tag_aliases", "tags" | ||||
add_foreign_key "user_ips", "ip_addresses" | add_foreign_key "user_ips", "ip_addresses" | ||||
@@ -131,6 +131,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_27_214100) do | |||||
add_foreign_key "user_post_views", "posts" | add_foreign_key "user_post_views", "posts" | ||||
add_foreign_key "user_post_views", "users" | add_foreign_key "user_post_views", "users" | ||||
add_foreign_key "wiki_pages", "tags" | add_foreign_key "wiki_pages", "tags" | ||||
add_foreign_key "wiki_pages", "users", column: "created_by_id" | |||||
add_foreign_key "wiki_pages", "users", column: "updated_by_id" | |||||
add_foreign_key "wiki_pages", "users", column: "created_user_id" | |||||
add_foreign_key "wiki_pages", "users", column: "updated_user_id" | |||||
end | end |
@@ -0,0 +1,11 @@ | |||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | |||||
# This model initially had no columns defined. If you add columns to the | |||||
# model remove the "{}" from the fixture names and add the columns immediately | |||||
# below each fixture, per the syntax in the comments below | |||||
# | |||||
one: {} | |||||
# column: value | |||||
# | |||||
two: {} | |||||
# column: value |
@@ -0,0 +1,11 @@ | |||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | |||||
# This model initially had no columns defined. If you add columns to the | |||||
# model remove the "{}" from the fixture names and add the columns immediately | |||||
# below each fixture, per the syntax in the comments below | |||||
# | |||||
one: {} | |||||
# column: value | |||||
# | |||||
two: {} | |||||
# column: value |
@@ -1,9 +1,11 @@ | |||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||||
one: | |||||
title: MyString | |||||
body: MyText | |||||
two: | |||||
title: MyString | |||||
body: MyText | |||||
# This model initially had no columns defined. If you add columns to the | |||||
# model remove the "{}" from the fixture names and add the columns immediately | |||||
# below each fixture, per the syntax in the comments below | |||||
# | |||||
one: {} | |||||
# column: value | |||||
# | |||||
two: {} | |||||
# column: value |
@@ -0,0 +1,11 @@ | |||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | |||||
# This model initially had no columns defined. If you add columns to the | |||||
# model remove the "{}" from the fixture names and add the columns immediately | |||||
# below each fixture, per the syntax in the comments below | |||||
# | |||||
one: {} | |||||
# column: value | |||||
# | |||||
two: {} | |||||
# column: value |
@@ -0,0 +1,11 @@ | |||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | |||||
# This model initially had no columns defined. If you add columns to the | |||||
# model remove the "{}" from the fixture names and add the columns immediately | |||||
# below each fixture, per the syntax in the comments below | |||||
# | |||||
one: {} | |||||
# column: value | |||||
# | |||||
two: {} | |||||
# column: value |
@@ -0,0 +1,7 @@ | |||||
require "test_helper" | |||||
class IpAddressTest < ActiveSupport::TestCase | |||||
# test "the truth" do | |||||
# assert true | |||||
# end | |||||
end |
@@ -0,0 +1,7 @@ | |||||
require "test_helper" | |||||
class NicoTagRelationTest < ActiveSupport::TestCase | |||||
# test "the truth" do | |||||
# assert true | |||||
# end | |||||
end |
@@ -0,0 +1,7 @@ | |||||
require "test_helper" | |||||
class TagTest < ActiveSupport::TestCase | |||||
# test "the truth" do | |||||
# assert true | |||||
# end | |||||
end |
@@ -0,0 +1,7 @@ | |||||
require "test_helper" | |||||
class UserTest < ActiveSupport::TestCase | |||||
# test "the truth" do | |||||
# assert true | |||||
# end | |||||
end |