From 23f7c3498605e1d95c5cb4ba51571f689e6bc0e2 Mon Sep 17 00:00:00 2001 From: Christina Chortaria Date: Tue, 16 Jul 2024 18:51:54 -0400 Subject: [PATCH 1/3] [#236] Add in library_staff_records table: areas_of_study,my_scheduler_link, other_entities Include areas_of_study and other_entities in virtual searchable column Rename column section to team Co-authored-by: Jane Sandberg --- Gemfile.lock | 1 + app/models/library_staff_record.rb | 3 ++ ...20240716210532_add_staff_records_fields.rb | 20 +++++++++ ...update_searchable_library_staff_records.rb | 44 +++++++++++++++++++ db/schema.rb | 9 ++-- 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20240716210532_add_staff_records_fields.rb create mode 100644 db/migrate/20240716214838_update_searchable_library_staff_records.rb diff --git a/Gemfile.lock b/Gemfile.lock index 914bb21..aa13055 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -304,6 +304,7 @@ PLATFORMS arm64-darwin-22 arm64-darwin-23 x86_64-darwin-22 + x86_64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/app/models/library_staff_record.rb b/app/models/library_staff_record.rb index ed82622..517faa8 100644 --- a/app/models/library_staff_record.rb +++ b/app/models/library_staff_record.rb @@ -34,6 +34,9 @@ def self.new_from_csv(row) record.building = row[8] record.department = row[9] record.unit = row[11] + record.areas_of_study = row[14]&.split('//') + record.my_scheduler_link = row[18] + record.other_entities = row[19]&.split('//') record.library_title = title record.title = title record.save! if record.valid? diff --git a/db/migrate/20240716210532_add_staff_records_fields.rb b/db/migrate/20240716210532_add_staff_records_fields.rb new file mode 100644 index 0000000..79d6ada --- /dev/null +++ b/db/migrate/20240716210532_add_staff_records_fields.rb @@ -0,0 +1,20 @@ +class AddStaffRecordsFields < ActiveRecord::Migration[7.1] + + def up + change_table :library_staff_records do |t| + t.column :areas_of_study, :string + t.column :other_entities, :string + t.column :my_scheduler_link, :string + t.rename :section, :team + end + end + def down + change_table :library_staff_records do |t| + t.remove :areas_of_study + t.remove :other_entities + t.remove :my_scheduler_link + t.rename :team, :section + end + end + +end diff --git a/db/migrate/20240716214838_update_searchable_library_staff_records.rb b/db/migrate/20240716214838_update_searchable_library_staff_records.rb new file mode 100644 index 0000000..0810519 --- /dev/null +++ b/db/migrate/20240716214838_update_searchable_library_staff_records.rb @@ -0,0 +1,44 @@ +class UpdateSearchableLibraryStaffRecords < ActiveRecord::Migration[7.1] + def up + change_table :library_staff_records do |t| + t.remove :searchable + t.virtual :searchable, type: :tsvector, + as: "to_tsvector('english', coalesce(title, '') || ' ' || " \ + "coalesce(first_name, '') || ' ' || " \ + "coalesce(middle_name, '') || ' ' || " \ + "coalesce(last_name, '') || ' ' || " \ + "coalesce(title, '') || ' ' || " \ + "coalesce(email, '') || ' ' || " \ + "coalesce(department, '') || ' ' || " \ + "coalesce(office, '') || ' ' || " \ + "coalesce(building, '') || ' ' || " \ + "coalesce(team, '') || ' ' || " \ + "coalesce(division, '') || ' ' || " \ + "coalesce(unit, '') || ' ' ||" \ + "coalesce(areas_of_study, '') || ' ' || " \ + "coalesce(other_entities, ''))", + stored: true + t.index ["searchable"], name: "staff_search_idx", using: :gin + end + end + + def down + change_table :library_staff_records do |t| + t.remove :searchable + t.virtual :searchable, type: :tsvector, + as: "to_tsvector('english', coalesce(title, '') || ' ' || " \ + "coalesce(first_name, '') || ' ' || " \ + "coalesce(middle_name, '') || ' ' || " \ + "coalesce(last_name, '') || ' ' || " \ + "coalesce(title, '') || ' ' || " \ + "coalesce(email, '') || ' ' || " \ + "coalesce(department, '') || ' ' || " \ + "coalesce(office, '') || ' ' || " \ + "coalesce(building, '') || ' ' || " \ + "coalesce(team, '') || ' ' || " \ + "coalesce(division, '') || ' ' || " \ + "coalesce(unit, ''))" , + stored: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 09ff810..5720507 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_07_10_210913) do +ActiveRecord::Schema[7.1].define(version: 2024_07_16_214838) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -51,7 +51,7 @@ t.string "title", null: false t.string "library_title", null: false t.string "email", null: false - t.string "section" + t.string "team" t.string "division" t.string "department" t.string "unit" @@ -59,7 +59,10 @@ t.string "building" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.virtual "searchable", type: :tsvector, as: "to_tsvector('english'::regconfig, (((((((((((((((((((((((COALESCE(title, ''::character varying))::text || ' '::text) || (COALESCE(first_name, ''::character varying))::text) || ' '::text) || (COALESCE(middle_name, ''::character varying))::text) || ' '::text) || (COALESCE(last_name, ''::character varying))::text) || ' '::text) || (COALESCE(title, ''::character varying))::text) || ' '::text) || (COALESCE(email, ''::character varying))::text) || ' '::text) || (COALESCE(department, ''::character varying))::text) || ' '::text) || (COALESCE(office, ''::character varying))::text) || ' '::text) || (COALESCE(building, ''::character varying))::text) || ' '::text) || (COALESCE(section, ''::character varying))::text) || ' '::text) || (COALESCE(division, ''::character varying))::text) || ' '::text) || (COALESCE(unit, ''::character varying))::text))", stored: true + t.string "areas_of_study" + t.string "other_entities" + t.string "my_scheduler_link" + t.virtual "searchable", type: :tsvector, as: "to_tsvector('english'::regconfig, (((((((((((((((((((((((((((COALESCE(title, ''::character varying))::text || ' '::text) || (COALESCE(first_name, ''::character varying))::text) || ' '::text) || (COALESCE(middle_name, ''::character varying))::text) || ' '::text) || (COALESCE(last_name, ''::character varying))::text) || ' '::text) || (COALESCE(title, ''::character varying))::text) || ' '::text) || (COALESCE(email, ''::character varying))::text) || ' '::text) || (COALESCE(department, ''::character varying))::text) || ' '::text) || (COALESCE(office, ''::character varying))::text) || ' '::text) || (COALESCE(building, ''::character varying))::text) || ' '::text) || (COALESCE(team, ''::character varying))::text) || ' '::text) || (COALESCE(division, ''::character varying))::text) || ' '::text) || (COALESCE(unit, ''::character varying))::text) || ' '::text) || (COALESCE(areas_of_study, ''::character varying))::text) || ' '::text) || (COALESCE(other_entities, ''::character varying))::text))", stored: true t.index ["searchable"], name: "staff_search_idx", using: :gin end From 55002c5d303cea41f42f39070afb8705bd3f62ec Mon Sep 17 00:00:00 2001 From: Christina Chortaria Date: Wed, 17 Jul 2024 18:12:14 -0400 Subject: [PATCH 2/3] [#236] Update library_staff_record to gsub other_entities and areas_of_study Now you can search or display other_entities and areas_of_study Include new fields in the csv loading header Update library staff record spec with new query for other_entities Co-authored-by: Jane Sandberg --- app/models/library_staff_record.rb | 4 ++-- app/services/library_staff_loading_service.rb | 2 +- .../library_staff/staff-directory-blank-lines.csv | 8 ++++---- spec/fixtures/files/library_staff/staff-directory.csv | 10 +++++----- spec/models/library_staff_record_spec.rb | 5 +++++ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/models/library_staff_record.rb b/app/models/library_staff_record.rb index 517faa8..20f4b73 100644 --- a/app/models/library_staff_record.rb +++ b/app/models/library_staff_record.rb @@ -34,9 +34,9 @@ def self.new_from_csv(row) record.building = row[8] record.department = row[9] record.unit = row[11] - record.areas_of_study = row[14]&.split('//') + record.areas_of_study = row[14]&.gsub('//', ', ') record.my_scheduler_link = row[18] - record.other_entities = row[19]&.split('//') + record.other_entities = row[19]&.gsub('//', ', ') record.library_title = title record.title = title record.save! if record.valid? diff --git a/app/services/library_staff_loading_service.rb b/app/services/library_staff_loading_service.rb index e9e9f36..c6f3b50 100644 --- a/app/services/library_staff_loading_service.rb +++ b/app/services/library_staff_loading_service.rb @@ -12,7 +12,7 @@ def class_to_load def expected_headers %w[puid netid phone name lastName firstName email address building department division - unit team title areasOfStudy websiteUrl bios expertise mySchedulerLink] + unit team title areasOfStudy websiteUrl bios expertise mySchedulerLink otherEntities] end def uri diff --git a/spec/fixtures/files/library_staff/staff-directory-blank-lines.csv b/spec/fixtures/files/library_staff/staff-directory-blank-lines.csv index 9aa84c6..e755390 100644 --- a/spec/fixtures/files/library_staff/staff-directory-blank-lines.csv +++ b/spec/fixtures/files/library_staff/staff-directory-blank-lines.csv @@ -1,4 +1,4 @@ -puid,netid,phone,name,lastName,firstName,email,address,building,department,division,unit,team,title,areasOfStudy,websiteUrl,bios,expertise,mySchedulerLink -,,,,,,,,,,,,,,,,,, -"000000001","lucyfs","(555) 123-1234","Stardust, Lucy","Stardust","Lucy Fae",lucyfs@princeton.edu,Forrestal,Recap Library,Office of the Deputy Dean of Libraries,Facilities,,,"Pest Removal Specialist",,,,, -,,,,,,,,,,,,,,,,,, +puid,netid,phone,name,lastName,firstName,email,address,building,department,division,unit,team,title,areasOfStudy,websiteUrl,bios,expertise,mySchedulerLink,otherEntities +,,,,,,,,,,,,,,,,,,, +"000000001","lucyfs","(555) 123-1234","Stardust, Lucy","Stardust","Lucy Fae",lucyfs@princeton.edu,Forrestal,Recap Library,Office of the Deputy Dean of Libraries,Facilities,,,"Pest Removal Specialist",,,,,, +,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/library_staff/staff-directory.csv b/spec/fixtures/files/library_staff/staff-directory.csv index b273fab..5baec64 100644 --- a/spec/fixtures/files/library_staff/staff-directory.csv +++ b/spec/fixtures/files/library_staff/staff-directory.csv @@ -1,5 +1,5 @@ -"puid","netid","phone","name","lastName","firstName",email,address,building,department,division,unit,team,"title","areasOfStudy","websiteUrl","bios","expertise","mySchedulerLink" -"000000001","lucyfs","(555) 123-1234","Stardust, Lucy","Stardust","Lucy Fae",lucyfs@princeton.edu,Forrestal,Recap Library,Office of the Deputy Dean of Libraries,Facilities,,,"Pest Removal Specialist",,,,, -"000000002","nimbuskt","(555) 111-1111","Trout, Nimbus","Trout","Nimbus Kilgore",nibmus@princeton.edu,A-200,Firestone Library,Office of the Deputy Dean of Libraries,Information Technology,IT Operations and Digitization,,"Nap Coordinator","Naps//Coordination",,,, -"000000003","tiberius","(555) 222-2222","Adams, Tiberius","Adams","Spot Tiberius",tiberius@princeton.edu,B-300,Firestone Library,My Department,Library - Collections and Access Services,Access & Fulfillment Services,,"Lead Hairball Engineer",,,,, -"000000010","brutus","(555) 222-2222","Cat, Brutus","Cat","Brutus The",brutus@princeton.edu,B-300,Stokes Library,My Department,Library - Collections and Access Services,PCRP - Physical Collections Receipt & Processing Unit,,"Fluffiest cat",,,,, +"puid","netid","phone","name","lastName","firstName",email,address,building,department,division,unit,team,"title","areasOfStudy","websiteUrl","bios","expertise","mySchedulerLink","otherEntities" +"000000001","lucyfs","(555) 123-1234","Stardust, Lucy","Stardust","Lucy Fae",lucyfs@princeton.edu,Forrestal,Recap Library,Office of the Deputy Dean of Libraries,Facilities,,,"Pest Removal Specialist",,,,,,"MS Chadha Center for Global India" +"000000002","nimbuskt","(555) 111-1111","Trout, Nimbus","Trout","Nimbus Kilgore",nibmus@princeton.edu,A-200,Firestone Library,Office of the Deputy Dean of Libraries,Information Technology,IT Operations and Digitization,,"Nap Coordinator","Naps//Coordination",,,,,"Center for Culture, Society and Religion//University Center for Human Values" +"000000003","tiberius","(555) 222-2222","Adams, Tiberius","Adams","Spot Tiberius",tiberius@princeton.edu,B-300,Firestone Library,My Department,Library - Collections and Access Services,Access & Fulfillment Services,,"Lead Hairball Engineer",,,,,,"Center for International Security Studies (CISS)//Center for the Study of Democratic Politics (CSDP)//Empirical Studies of Conflict (ESOC)//Innovations for Successful Societies (ISS)//Liechtenstein Institute on Self-Determination (LISD)//Niehaus Center for lization and Governance (NCGG)//Princeton Survey Research Center (SRC)//Research Program in Political Economy (RPPE)" +"000000010","brutus","(555) 222-2222","Cat, Brutus","Cat","Brutus The",brutus@princeton.edu,B-300,Stokes Library,My Department,Library - Collections and Access Services,PCRP - Physical Collections Receipt & Processing Unit,,"Fluffiest cat",,,,,, diff --git a/spec/models/library_staff_record_spec.rb b/spec/models/library_staff_record_spec.rb index 3d0e9b2..adbd563 100644 --- a/spec/models/library_staff_record_spec.rb +++ b/spec/models/library_staff_record_spec.rb @@ -30,5 +30,10 @@ expect(results[0].first_name).to eq('Nimbus Kilgore') expect(results[1].first_name).to eq('Spot Tiberius') end + it "finds records by other entities" do + results = described_class.query('Center for Global') + expect(results.length).to eq(1) + expect(results[0].other_entities).to eq('MS Chadha Center for Global India') + end end end From e76723549df96830aeaa3a1e5d45f77a29a25f86 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Thu, 18 Jul 2024 11:35:50 -0700 Subject: [PATCH 3/3] [#236] Rename section to team Co-authored-by: Christina Chortaria --- app/models/library_staff_document.rb | 6 +++--- spec/models/library_staff_record_spec.rb | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/library_staff_document.rb b/app/models/library_staff_document.rb index aa73a2c..3cd3c6c 100644 --- a/app/models/library_staff_document.rb +++ b/app/models/library_staff_document.rb @@ -50,8 +50,8 @@ def library_title document.library_title end - def section - document.section + def team + document.team end def division @@ -89,7 +89,7 @@ def url end def doc_keys - [:first_name, :middle_name, :last_name, :netid, :library_title, :phone, :email, :section, :division, :department, + [:first_name, :middle_name, :last_name, :netid, :library_title, :phone, :email, :team, :division, :department, :unit, :office, :building] end end diff --git a/spec/models/library_staff_record_spec.rb b/spec/models/library_staff_record_spec.rb index adbd563..c6f2ac2 100644 --- a/spec/models/library_staff_record_spec.rb +++ b/spec/models/library_staff_record_spec.rb @@ -30,7 +30,8 @@ expect(results[0].first_name).to eq('Nimbus Kilgore') expect(results[1].first_name).to eq('Spot Tiberius') end - it "finds records by other entities" do + + it 'finds records by other entities' do results = described_class.query('Center for Global') expect(results.length).to eq(1) expect(results[0].other_entities).to eq('MS Chadha Center for Global India')