Skip to content

Commit

Permalink
Fix optional parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
JaciBrunning committed Jul 21, 2019
1 parent 16a472e commit 528c255
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 2 additions & 4 deletions app/jobs/update_single_course_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ def update_unit url, course, org

# Bind the unit to a course

bind = CourseUnit.find_or_initialize_by(course: course, unit: unit)
bind = CourseUnit.find_or_initialize_by(course: course, unit: unit, planned_period: org[:planned])
bind.optional = org[:optional]
bind.planned_period = org[:planned]
bind.planned_level = org[:planned_lvl]
bind.save
end
Expand All @@ -162,9 +161,8 @@ def update_freeform course, org
unit.freeform_period = org[:unit][:freeform_period] unless org[:freeform] == :elective
unit.save

bind = CourseUnit.find_or_initialize_by(course: course, unit: unit)
bind = CourseUnit.find_or_initialize_by(course: course, unit: unit, planned_period: org[:course_unit][:planned])
bind.optional = org[:course_unit][:optional]
bind.planned_period = org[:course_unit][:planned]
bind.planned_level = org[:course_unit][:planned_lvl]
bind.save
end
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20190721102230_fix_course_unit_optionals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class FixCourseUnitOptionals < ActiveRecord::Migration[5.2]
def up
remove_index :course_units, name: :index_course_units_on_course_id_and_unit_id
add_index :course_units, [:course_id, :unit_id, :planned_period], unique: true, name: :index_course_units_uniq
end

def down
add_index :course_units, [:course_id, :unit_id], unique: true
remove_index :course_units, name: :index_course_units_uniq
end
end
4 changes: 2 additions & 2 deletions 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.define(version: 2019_07_21_042559) do
ActiveRecord::Schema.define(version: 2019_07_21_102230) do

create_table "course_units", force: :cascade do |t|
t.integer "course_id"
Expand All @@ -20,7 +20,7 @@
t.string "planned_period"
t.integer "planned_level", default: 0
t.boolean "optional", default: false
t.index ["course_id", "unit_id"], name: "index_course_units_on_course_id_and_unit_id", unique: true
t.index ["course_id", "unit_id", "planned_period"], name: "index_course_units_uniq", unique: true
t.index ["course_id"], name: "index_course_units_on_course_id"
t.index ["unit_id"], name: "index_course_units_on_unit_id"
end
Expand Down

0 comments on commit 528c255

Please sign in to comment.