Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TGR update readme and ES setup #1462

Closed
wants to merge 2 commits into from
Closed
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
53 changes: 3 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ The app will be available at `http://localhost:3000`.
Data
====

To create and seed the database:

Load schema and data (from within the webapp container):

```
bundle exec rake db:create db:migrate db:seed
```
Locally, the development and test Postgres databases should be created and set up automatically.

To dump data to seed-data dump file (i.e. for use by other devs):

Expand Down Expand Up @@ -53,11 +47,6 @@ If the school is not found by zcode, the rake task will create a new record. If
Testing
========================

First, set up a test database:
```
RAILS_ENV=test bundle exec rake db:drop db:create db:schema:load
```

For the unit tests and integration tests, please run the following command inside a webapp container while in the root directory.

```
Expand Down Expand Up @@ -101,7 +90,7 @@ Setting Up ElasticSearch locally
=================================

```
The MylibraryNyc project uses elastic-search-6.8.
The MylibraryNyc project uses elastic-search-7.10

Make sure the elasticsearch container is running. Then, enter into a webapp container.

Expand All @@ -111,43 +100,7 @@ If that doesn't work, you can try 'sh script.elastic_search/delete_es_mappings.s

Enter the local elasticsearch URL (currently http://elasticsearch:9200)

Run the code below in a rails console to update teacherset doc data in the elasticsearch cluster.

TeacherSet.find_each do |ts|
arr = []
created_at = ts.created_at.present? ? ts.created_at.strftime("%Y-%m-%dT%H:%M:%S%z") : nil
updated_at = ts.updated_at.present? ? ts.updated_at.strftime("%Y-%m-%dT%H:%M:%S%z") : nil
availability = ts.availability.present? ? ts.availability.downcase : nil
begin
subjects_arr = []
if ts.subjects.present?
ts.subjects.uniq.each do |subject|
subjects_hash = {}
s_created_at = subject.created_at.present? ? subject.created_at.strftime("%Y-%m-%dT%H:%M:%S%z") : nil
s_updated_at = subject.updated_at.present? ? subject.updated_at.strftime("%Y-%m-%dT%H:%M:%S%z") : nil
subjects_hash[:id] = subject.id
subjects_hash[:title] = subject.title
subjects_hash[:created_at] = s_created_at
subjects_hash[:updated_at] = s_updated_at
subjects_arr << subjects_hash
end
end
body = {title: ts.title, description: ts.description, contents: ts.contents,
id: ts.id.to_i, details_url: ts.details_url, grade_end: ts.grade_end,
grade_begin: ts.grade_begin, availability: availability, total_copies: ts.total_copies,
call_number: ts.call_number, language: ts.language, physical_description: ts.physical_description,
primary_language: ts.primary_language, created_at: created_at, updated_at: updated_at,
available_copies: ts.available_copies, bnumber: ts.bnumber, set_type: ts.set_type,
area_of_study: ts.area_of_study, subjects: subjects_arr}
ElasticSearch.new.create_document(ts.id, body)
puts "updating elastic search"
rescue Elasticsearch::Transport::Transport::Errors::Conflict => e
puts "Error in elastic search"
arr << ts.id
end
arr
end

Do `bundle exec rake seeds:teacher_sets` to seed the teacher set data in the development elasticsearch instance.
```


Expand Down
60 changes: 60 additions & 0 deletions lib/tasks/seed_teacher_sets.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace :seeds do
desc "Seed Teacher Sets in Elasticsearch"

task teacher_sets: :environment do
failed = []

TeacherSet.find_each do |ts|
created_at = ts.created_at.present? ? ts.created_at.strftime("%Y-%m-%dT%H:%M:%S%z") : nil
updated_at = ts.updated_at.present? ? ts.updated_at.strftime("%Y-%m-%dT%H:%M:%S%z") : nil
availability = ts.availability.present? ? ts.availability.downcase : nil

begin
subjects_arr = []

if ts.subjects.present?
ts.subjects.uniq.each do |subject|
subjects_hash = {}
s_created_at = subject.created_at.present? ? subject.created_at.strftime("%Y-%m-%dT%H:%M:%S%z") : nil
s_updated_at = subject.updated_at.present? ? subject.updated_at.strftime("%Y-%m-%dT%H:%M:%S%z") : nil
subjects_hash[:id] = subject.id
subjects_hash[:title] = subject.title
subjects_hash[:created_at] = s_created_at
subjects_hash[:updated_at] = s_updated_at
subjects_arr << subjects_hash
end
end

body = {
title: ts.title,
description: ts.description,
contents: ts.contents,
id: ts.id.to_i,
details_url: ts.details_url,
grade_end: ts.grade_end,
grade_begin: ts.grade_begin,
availability: availability,
total_copies: ts.total_copies,
call_number: ts.call_number,
language: ts.language,
physical_description: ts.physical_description,
primary_language: ts.primary_language,
created_at: created_at,
updated_at: updated_at,
available_copies: ts.available_copies,
bnumber: ts.bnumber,
set_type: ts.set_type,
area_of_study: ts.area_of_study,
subjects: subjects_arr
}

ElasticSearch.new.create_document(ts.id, body)
puts "updating elastic search"
rescue Elasticsearch::Transport::Transport::Errors::Conflict => e
puts "Error in elastic search: #{e.inspect}"
failed << ts.id
end
end
puts "Teacher sets with ids #{failed} not created" unless failed.empty?
end
end