From 3f2c0a52b973751a8eb8114ed2eae21cce946059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BF=E3=81=A6=E3=82=8B=E3=81=9E?= Date: Tue, 6 Jan 2026 12:43:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20posts.thumbnail=5Fbase=20=E3=82=92=20Nu?= =?UTF-8?q?llable=20=E3=81=AB=EF=BC=88#75=EF=BC=89=20(#198)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge remote-tracking branch 'origin/main' into feature/075 #75 Co-authored-by: miteruzo Reviewed-on: https://git.miteruzo.com/miteruzo/btrc-hub/pulls/198 --- backend/app/controllers/posts_controller.rb | 2 +- ...0_make_thumbnail_base_nullable_in_posts.rb | 27 +++++++++++++++++++ backend/db/schema.rb | 4 +-- backend/lib/tasks/sync_nico.rake | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 backend/db/migrate/20251230143400_make_thumbnail_base_nullable_in_posts.rb diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index ce555ed..a3a4538 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -88,7 +88,7 @@ class PostsController < ApplicationController original_created_from = params[:original_created_from] original_created_before = params[:original_created_before] - post = Post.new(title:, url:, thumbnail_base: '', uploaded_user: current_user, + post = Post.new(title:, url:, thumbnail_base: nil, uploaded_user: current_user, original_created_from:, original_created_before:) post.thumbnail.attach(thumbnail) if post.save diff --git a/backend/db/migrate/20251230143400_make_thumbnail_base_nullable_in_posts.rb b/backend/db/migrate/20251230143400_make_thumbnail_base_nullable_in_posts.rb new file mode 100644 index 0000000..f9da7c0 --- /dev/null +++ b/backend/db/migrate/20251230143400_make_thumbnail_base_nullable_in_posts.rb @@ -0,0 +1,27 @@ +class MakeThumbnailBaseNullableInPosts < ActiveRecord::Migration[7.0] + def up + change_column_null :posts, :thumbnail_base, true + + execute <<~SQL + UPDATE + posts + SET + thumbnail_base = NULL + WHERE + thumbnail_base = '' + SQL + end + + def down + execute <<~SQL + UPDATE + posts + SET + thumbnail_base = '' + WHERE + thumbnail_base IS NULL + SQL + + change_column_null :posts, :thumbnail_base, false + end +end diff --git a/backend/db/schema.rb b/backend/db/schema.rb index 116a1a2..697bd8f 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_29_022100) do +ActiveRecord::Schema[8.0].define(version: 2025_12_30_143400) 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 @@ -86,7 +86,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_12_29_022100) do create_table "posts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "title", null: false t.string "url", limit: 2000, null: false - t.string "thumbnail_base", limit: 2000, null: false + t.string "thumbnail_base", limit: 2000 t.bigint "parent_id" t.bigint "uploaded_user_id" t.datetime "created_at", null: false diff --git a/backend/lib/tasks/sync_nico.rake b/backend/lib/tasks/sync_nico.rake index d20150c..d09a424 100644 --- a/backend/lib/tasks/sync_nico.rake +++ b/backend/lib/tasks/sync_nico.rake @@ -49,7 +49,7 @@ namespace :nico do unless post title = datum['title'] url = "https://www.nicovideo.jp/watch/#{ datum['code'] }" - thumbnail_base = fetch_thumbnail.(url) || '' rescue '' + thumbnail_base = fetch_thumbnail.(url) rescue nil post = Post.new(title:, url:, thumbnail_base:, uploaded_user: nil) if thumbnail_base.present? post.thumbnail.attach(