This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class UserIp < ApplicationRecord
|
||||
self.primary_key = :user_id, :ip_address_id
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :ip_address
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
class ChangeUserIpsToCompositePk < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
execute <<~SQL
|
||||
ALTER TABLE
|
||||
user_ips
|
||||
MODIFY COLUMN id BIGINT NOT NULL
|
||||
;
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
ALTER TABLE
|
||||
user_ips
|
||||
DROP PRIMARY KEY
|
||||
;
|
||||
SQL
|
||||
|
||||
remove_column :user_ips, :id
|
||||
|
||||
execute <<~SQL
|
||||
ALTER TABLE
|
||||
user_ips
|
||||
ADD PRIMARY KEY (user_id, ip_address_id)
|
||||
;
|
||||
SQL
|
||||
|
||||
remove_index :user_ips, name: 'index_user_ips_on_user_id'
|
||||
end
|
||||
|
||||
def down
|
||||
execute <<~SQL
|
||||
ALTER TABLE
|
||||
user_ips
|
||||
DROP PRIMARY KEY
|
||||
;
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
ALTER TABLE
|
||||
user_ips
|
||||
ADD COLUMN id BIGINT NOT NULL AUTO_INCREMENT FIRST
|
||||
, ADD PRIMARY KEY (id)
|
||||
;
|
||||
SQL
|
||||
|
||||
add_index :user_ips, :user_id, name: 'index_user_ips_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.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_01_26_124100) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_01_27_000900) 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
|
||||
@@ -144,13 +144,12 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_26_124100) do
|
||||
t.index ["tag_name_id"], name: "index_tags_on_tag_name_id", unique: true
|
||||
end
|
||||
|
||||
create_table "user_ips", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
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"
|
||||
t.index ["user_id"], name: "index_user_ips_on_user_id"
|
||||
end
|
||||
|
||||
create_table "user_post_views", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
|
||||
Reference in New Issue
Block a user