-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add omit_from_final_grade to course config
refs TALLY-301 test plan: - migration runs Change-Id: Ic8ba3cb0db3c722bd1e804dd28d2b3e6957b383f Reviewed-on: https://gerrit.instructure.com/c/rollcall-attendance/+/217597 Tested-by: Service Cloud Jenkins <[email protected]> Reviewed-by: Simon Williams <[email protected]> QA-Review: Spencer Olson <[email protected]> Product-Review: Keith Garner <[email protected]>
- Loading branch information
Showing
6 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
db/migrate/20191118151647_add_omit_from_final_grade_to_course_config.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Copyright (C) 2019 - present Instructure, Inc. | ||
# | ||
# This file is part of Rollcall. | ||
# | ||
# Rollcall is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Affero General Public License as published by the Free | ||
# Software Foundation, version 3 of the License. | ||
# | ||
# Rollcall is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
class AddOmitFromFinalGradeToCourseConfig < ActiveRecord::Migration[5.2] | ||
disable_ddl_transaction! | ||
|
||
def up | ||
if ActiveRecord::ConnectionAdapters.const_defined?("Mysql2Adapter") && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) | ||
# Look at https://dev.mysql.com/doc/refman/5.6/en/innodb-online-ddl-operations.html#online-ddl-column-operations | ||
# for some additional information. We're trying to do the database changes in place without needing a copy table, | ||
# the MySQL default. We're on a new enough MySQL that we should be able to the add the column, set the default, | ||
# and set it NOT NULL all without a copy nor a lock. | ||
execute <<~SQL | ||
ALTER TABLE course_configs | ||
ADD COLUMN omit_from_final_grade BOOL DEFAULT false NOT NULL, | ||
ALGORITHM=INPLACE, | ||
LOCK=NONE; | ||
SQL | ||
else | ||
add_column :course_configs, :omit_from_final_grade, :boolean | ||
change_column_default :course_configs, :omit_from_final_grade, false | ||
DataFixup::BackfillNulls.run(CourseConfig, :omit_from_final_grade, new_value: false, batch_size: 1000) | ||
change_column_null(:course_configs, :omit_from_final_grade, false) | ||
end | ||
end | ||
|
||
def down | ||
remove_column :course_configs, :omit_from_final_grade | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (C) 2019 - present Instructure, Inc. | ||
# | ||
# This file is part of Rollcall. | ||
# | ||
# Rollcall is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Affero General Public License as published by the Free | ||
# Software Foundation, version 3 of the License. | ||
# | ||
# Rollcall is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
module DataFixup::BackfillNulls | ||
def self.run(klass, field, new_value:, batch_size: 1000) | ||
objects_to_backfill = klass.where(field => nil) | ||
objects_to_backfill.in_batches(of: batch_size).update_all(field => new_value, updated_at: Time.zone.now) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
|
||
describe DataFixup::BackfillNulls do | ||
context '.run' do | ||
before do | ||
@course1 = create(:course_config, course_id: 1234, tardy_weight: nil) | ||
@course2 = create(:course_config, course_id: 1235, tardy_weight: 0.8) | ||
end | ||
|
||
it 'replaces null values of "field" with the new value' do | ||
expect { | ||
DataFixup::BackfillNulls.run(CourseConfig, :tardy_weight, new_value: 0.5) | ||
}.to change { @course1.reload.tardy_weight }.from(nil).to(0.5) | ||
end | ||
|
||
it 'does not replace not-null values of "field"' do | ||
expect { | ||
DataFixup::BackfillNulls.run(CourseConfig, :tardy_weight, new_value: 0.5) | ||
}.not_to change { @course2.reload.tardy_weight }.from(0.8) | ||
end | ||
end | ||
end |