feat: user_post_views から id を削除(#230) (#239)

#230

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #239
このコミットはPull リクエスト #239 でマージされました.
このコミットが含まれているのは:
2026-01-27 01:04:16 +09:00
コミット 19c622c5bf
3個のファイルの変更51行の追加3行の削除
+47
ファイルの表示
@@ -0,0 +1,47 @@
class ChangeUserPostViewsToCompositePk < ActiveRecord::Migration[8.0]
def up
execute <<~SQL
ALTER TABLE
user_post_views
MODIFY COLUMN id BIGINT NOT NULL
;
SQL
execute <<~SQL
ALTER TABLE
user_post_views
DROP PRIMARY KEY
;
SQL
remove_column :user_post_views, :id
execute <<~SQL
ALTER TABLE
user_post_views
ADD PRIMARY KEY (user_id, post_id)
;
SQL
remove_index :user_post_views, name: 'index_user_post_views_on_user_id'
end
def down
execute <<~SQL
ALTER TABLE
user_post_views
DROP PRIMARY KEY
;
SQL
execute <<~SQL
ALTER TABLE
user_post_views
ADD COLUMN id BIGINT NOT NULL AUTO_INCREMENT FIRST
, ADD PRIMARY KEY (id)
;
SQL
add_index :user_post_views, :user_id, name: 'index_user_post_views_on_user_id'
end
end