This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
class PostSimilarity < ApplicationRecord
|
class PostSimilarity < ApplicationRecord
|
||||||
|
self.primary_key = :post_id, :target_post_id
|
||||||
|
|
||||||
belongs_to :post, class_name: 'Post', foreign_key: 'post_id'
|
belongs_to :post, class_name: 'Post', foreign_key: 'post_id'
|
||||||
belongs_to :target_post, class_name: 'Post', foreign_key: 'target_post_id'
|
belongs_to :target_post, class_name: 'Post', foreign_key: 'target_post_id'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
class TagSimilarity < ApplicationRecord
|
class TagSimilarity < ApplicationRecord
|
||||||
|
self.primary_key = :tag_id, :target_tag_id
|
||||||
|
|
||||||
belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id'
|
belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id'
|
||||||
belongs_to :target_tag, class_name: 'Tag', foreign_key: 'target_tag_id'
|
belongs_to :target_tag, class_name: 'Tag', foreign_key: 'target_tag_id'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
class ChangePostSimilaritiesToCompositePk < ActiveRecord::Migration[8.0]
|
||||||
|
def up
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
post_similarities
|
||||||
|
MODIFY COLUMN id BIGINT NOT NULL
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
post_similarities
|
||||||
|
DROP PRIMARY KEY
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
remove_column :post_similarities, :id
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
post_similarities
|
||||||
|
ADD PRIMARY KEY (post_id, target_post_id)
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
post_similarities
|
||||||
|
DROP PRIMARY KEY
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
post_similarities
|
||||||
|
ADD COLUMN id BIGINT NOT NULL AUTO_INCREMENT FIRST
|
||||||
|
, ADD PRIMARY KEY (id)
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
class ChangeTagSimilaritiesToCompositePk < ActiveRecord::Migration[8.0]
|
||||||
|
def up
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
tag_similarities
|
||||||
|
MODIFY COLUMN id BIGINT NOT NULL
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
tag_similarities
|
||||||
|
DROP PRIMARY KEY
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
remove_column :tag_similarities, :id
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
tag_similarities
|
||||||
|
ADD PRIMARY KEY (tag_id, target_tag_id)
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
tag_similarities
|
||||||
|
DROP PRIMARY KEY
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
ALTER TABLE
|
||||||
|
tag_similarities
|
||||||
|
ADD COLUMN id BIGINT NOT NULL AUTO_INCREMENT FIRST
|
||||||
|
, ADD PRIMARY KEY (id)
|
||||||
|
;
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
end
|
||||||
Generated
+3
-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_18_144400) do
|
ActiveRecord::Schema[8.0].define(version: 2026_01_21_024800) 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
|
||||||
@@ -55,7 +55,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_18_144400) do
|
|||||||
t.index ["tag_id"], name: "index_nico_tag_relations_on_tag_id"
|
t.index ["tag_id"], name: "index_nico_tag_relations_on_tag_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "post_similarities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "post_similarities", primary_key: ["post_id", "target_post_id"], 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 "target_post_id", null: false
|
t.bigint "target_post_id", null: false
|
||||||
t.float "cos", null: false
|
t.float "cos", null: false
|
||||||
@@ -126,7 +126,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_18_144400) do
|
|||||||
t.index ["name"], name: "index_tag_names_on_name", unique: true
|
t.index ["name"], name: "index_tag_names_on_name", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "tag_similarities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "tag_similarities", primary_key: ["tag_id", "target_tag_id"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.bigint "tag_id", null: false
|
t.bigint "tag_id", null: false
|
||||||
t.bigint "target_tag_id", null: false
|
t.bigint "target_tag_id", null: false
|
||||||
t.float "cos", null: false
|
t.float "cos", null: false
|
||||||
|
|||||||
Reference in New Issue
Block a user