Skip to content

Commit

Permalink
Merge pull request #14163 from danidoni/add-missing-notified-projects…
Browse files Browse the repository at this point in the history
…-project-id-index

Add missing index on notified_project's project_id
  • Loading branch information
eduardoj committed Apr 27, 2023
2 parents 6205715 + ea30b72 commit a7bb6dc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/api/.database_consistency.todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2090,9 +2090,6 @@ NotifiedProject:
notification:
ForeignKeyChecker:
enabled: false
project:
ForeignKeyChecker:
enabled: false
index_notified_projects_on_notification_id:
RedundantIndexChecker:
enabled: false
Expand Down
7 changes: 6 additions & 1 deletion src/api/app/models/notified_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ class NotifiedProject < ApplicationRecord
# id :bigint not null, primary key
# created_at :datetime not null
# notification_id :bigint not null, indexed, indexed => [project_id]
# project_id :integer not null, indexed => [notification_id]
# project_id :integer not null, indexed => [notification_id], indexed
#
# Indexes
#
# index_notified_projects_on_notification_id (notification_id)
# index_notified_projects_on_notification_id_and_project_id (notification_id,project_id) UNIQUE
# index_notified_projects_on_project_id (project_id)
#
# Foreign Keys
#
# fk_rails_... (project_id => projects.id)
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNotifiedProjectsProjectIdIndex < ActiveRecord::Migration[7.0]
def change
add_index :notified_projects, :project_id
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProjectsIdNotifiedProjectsProjectIdFk < ActiveRecord::Migration[7.0]
def change
add_foreign_key :notified_projects, :projects, column: :project_id, primary_key: :id
end
end
4 changes: 3 additions & 1 deletion src/api/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_04_13_080503) do
ActiveRecord::Schema[7.0].define(version: 2023_04_14_151119) do
create_table "architectures", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.string "name", null: false, collation: "utf8mb3_general_ci"
t.boolean "available", default: false
Expand Down Expand Up @@ -703,6 +703,7 @@
t.datetime "created_at", null: false
t.index ["notification_id", "project_id"], name: "index_notified_projects_on_notification_id_and_project_id", unique: true
t.index ["notification_id"], name: "index_notified_projects_on_notification_id"
t.index ["project_id"], name: "index_notified_projects_on_project_id"
end

create_table "package_issues", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
Expand Down Expand Up @@ -1182,6 +1183,7 @@
add_foreign_key "kiwi_packages", "kiwi_package_groups", column: "package_group_id"
add_foreign_key "maintained_projects", "projects", column: "maintenance_project_id", name: "maintained_projects_ibfk_2"
add_foreign_key "maintained_projects", "projects", name: "maintained_projects_ibfk_1"
add_foreign_key "notified_projects", "projects"
add_foreign_key "package_issues", "issues", name: "package_issues_ibfk_2"
add_foreign_key "package_issues", "packages", name: "package_issues_ibfk_1"
add_foreign_key "package_kinds", "packages", name: "package_kinds_ibfk_1"
Expand Down
7 changes: 5 additions & 2 deletions src/api/spec/db/data/backfill_notified_projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@
end

it 'backfills the notifications_projects table with all projects from existing notifications' do
expect(NotifiedProject.pluck(:project_id)).to eq([
expected = NotifiedProject.pluck(:project_id)
actual = [
bs_request_with_submit_action.target_project_objects.distinct.map(&:id),
user_review.bs_request.target_project_objects.distinct.map(&:id),
comment_project.commentable.id,
comment_package.commentable.project_id,
comment_request.commentable.target_project_objects.distinct.map(&:id)
].flatten!)
].flatten!

expect(expected).to match_array(actual)
end
end
end

0 comments on commit a7bb6dc

Please sign in to comment.