feat: user_post_views から id を削除(#230) (#239)
#230 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #239
This commit was merged in pull request #239.
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
class UserPostView < ApplicationRecord
|
class UserPostView < ApplicationRecord
|
||||||
|
self.primary_key = :user_id, :post_id
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
Generated
+2
-3
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2026_01_27_000900) do
|
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|
|
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
@@ -152,13 +152,12 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_27_000900) do
|
|||||||
t.index ["ip_address_id"], name: "index_user_ips_on_ip_address_id"
|
t.index ["ip_address_id"], name: "index_user_ips_on_ip_address_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "user_post_views", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
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 "user_id", null: false
|
||||||
t.bigint "post_id", null: false
|
t.bigint "post_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 ["post_id"], name: "index_user_post_views_on_post_id"
|
t.index ["post_id"], name: "index_user_post_views_on_post_id"
|
||||||
t.index ["user_id"], name: "index_user_post_views_on_user_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
|
|||||||
Reference in New Issue
Block a user