Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/models/cx_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ def duplicate!(new_user:)
end

def self.to_csv
collections = all.includes(:organization, :service_provider, :service, :user).references(:organization).order(:fiscal_year, :quarter, 'organizations.name')
collections = all
.includes(:organization, :service, :user, :cx_collection_details, service_provider: :organization)
.references(:organization)
.order(:fiscal_year, :quarter, 'organizations.name')

attributes = %i[
id
Expand Down Expand Up @@ -118,7 +121,7 @@ def self.to_csv
csv << attributes

collections.each do |collection|
csv << attributes = [
csv << [
collection.id,
collection.name,
collection.organization_id,
Expand Down
4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class User < ApplicationRecord

def cx_collections
user_org = organization
user_parent_org = user_org&.parent
return CxCollection.none if user_org.nil?

user_parent_org = user_org.parent

CxCollection.where(cx_collections: { organization_id: [user_org.id, user_parent_org&.id].compact })
end
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20251210192727_add_indexes_to_cx_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class AddIndexesToCxCollections < ActiveRecord::Migration[8.0]
def change
# cx_collections table - missing all FK indexes
add_index :cx_collections, :organization_id
add_index :cx_collections, :user_id
add_index :cx_collections, :service_provider_id
add_index :cx_collections, :service_id

# cx_collection_details table - missing FK index
add_index :cx_collection_details, :cx_collection_id

# cx_responses table - missing FK indexes
add_index :cx_responses, :cx_collection_detail_id
add_index :cx_responses, :cx_collection_detail_upload_id
end
end
9 changes: 8 additions & 1 deletion 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[8.0].define(version: 2025_07_17_034402) do
ActiveRecord::Schema[8.0].define(version: 2025_12_10_192727) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"

Expand Down Expand Up @@ -97,6 +97,7 @@
t.text "trust_question_text"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["cx_collection_id"], name: "index_cx_collection_details_on_cx_collection_id"
end

create_table "cx_collections", force: :cascade do |t|
Expand Down Expand Up @@ -124,6 +125,10 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "submitted_at"
t.index ["organization_id"], name: "index_cx_collections_on_organization_id"
t.index ["service_id"], name: "index_cx_collections_on_service_id"
t.index ["service_provider_id"], name: "index_cx_collections_on_service_provider_id"
t.index ["user_id"], name: "index_cx_collections_on_user_id"
end

create_table "cx_responses", force: :cascade do |t|
Expand All @@ -149,6 +154,8 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "external_id"
t.index ["cx_collection_detail_id"], name: "index_cx_responses_on_cx_collection_detail_id"
t.index ["cx_collection_detail_upload_id"], name: "index_cx_responses_on_cx_collection_detail_upload_id"
end

create_table "digital_product_versions", force: :cascade do |t|
Expand Down
Loading