canvas-lms/db/migrate/20171208202812_create_discu...

51 lines
2.2 KiB
Ruby
Raw Normal View History

Create a table for section specific announcements. This creates a column in discussion_topics called "is_section_specific" and also creates a table for storing which sections go to which announcements. Right now, as long as the section_specific_announcements feature is disabled, it will not be possible to use rails to set this new column to true, or add stuff to the new table, so these tables should be frozen to empty. Closes COMMS-550 Closes COMMS-551 Test Plan: * Have a course with sections and discussion topics in it. * Run "bundle exec rake db:migrate:up VERSION=20171208202812" * Run "bundle exec rake db:migrate:up VERSION=20171208202825" * "rails dbconsole" * Verify that "is_section_specific" is present in the discussion_topics table and that it cannot be null. * Verify that "is_section_specific" has an explicit false value in each row. * Run "bundle exec rake db:migrate:down VERSION=20171208202825" * Run "bundle exec rake db:migrate:down VERSION=20171208202812" * (The order in which you run these migrations matters) * Needless to say, the above stuff should all succeed. * Specs pass. * Make sure that, if the feature is disabled, we can't set the is_section_specific column to true and we can't put stuff in the new table. Change-Id: I2b6e75872a1380a481d2ad15fca3d7e1b257a542 Reviewed-on: https://gerrit.instructure.com/135021 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Steven Burnett <sburnett@instructure.com> Tested-by: Jenkins QA-Review: Felix Milea-Ciobanu <fmileaciobanu@instructure.com> Product-Review: Venk Natarajan <vnatarajan@instructure.com>
2017-12-08 07:51:21 +08:00
# Copyright (C) 2017 - 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 CreateDiscussionTopicSectionVisibilities < ActiveRecord::Migration[5.0]
tag :predeploy
def up
create_table :discussion_topic_section_visibilities do |t|
t.integer :discussion_topic_id, null: false, limit: 8
t.integer :course_section_id, null: false, limit: 8
t.timestamps null: false
t.string :workflow_state, null: false, limit: 255
end
add_foreign_key :discussion_topic_section_visibilities, :discussion_topics
add_foreign_key :discussion_topic_section_visibilities, :course_sections
add_index :discussion_topic_section_visibilities, :discussion_topic_id,
name: "idx_discussion_topic_section_visibility_on_topic"
add_index :discussion_topic_section_visibilities, :course_section_id,
name: "idx_discussion_topic_section_visibility_on_section"
add_column :discussion_topics, :is_section_specific, :boolean
change_column_default :discussion_topics, :is_section_specific, false
end
def down
remove_column :discussion_topics, :is_section_specific
remove_index(:discussion_topic_section_visibilities,
{ :name=>"idx_discussion_topic_section_visibility_on_section" })
remove_index(:discussion_topic_section_visibilities,
{ :name=>"idx_discussion_topic_section_visibility_on_topic" })
remove_foreign_key(:discussion_topic_section_visibilities, :course_sections)
remove_foreign_key(:discussion_topic_section_visibilities, :discussion_topics)
drop_table(:discussion_topic_section_visibilities, { :id => :bigserial })
end
end