canvas-lms/db/migrate/20141029163245_create_gradi...

38 lines
1.2 KiB
Ruby
Raw Normal View History

#
# Copyright (C) 2014 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas 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.
#
# Canvas 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 CreateGradingPeriodGroups < ActiveRecord::Migration[4.2]
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
tag :predeploy
def self.up
create_table :grading_period_groups do |t|
t.integer :course_id, :limit => 8
t.integer :account_id, :limit => 8
t.timestamps null: true
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
end
add_foreign_key :grading_period_groups, :courses
add_foreign_key :grading_period_groups, :accounts
add_index :grading_period_groups, :course_id
add_index :grading_period_groups, :account_id
end
def self.down
drop_table :grading_period_groups
end
end