squash old migrations, p3
Change-Id: I6317d228aaef4ae38c03a681b67ffe1a6f815e3f Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/223048 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
02db0270ec
commit
63921c7a3b
|
@ -28,7 +28,7 @@ class ValidateMigrationIntegrity < ActiveRecord::Migration[4.2]
|
|||
|
||||
def self.up
|
||||
initial_migration_version = "20101210192618"
|
||||
last_squashed_migration_version = "20110606160200"
|
||||
last_squashed_migration_version = "20110817173455"
|
||||
|
||||
initial_migration_has_run = ActiveRecord::SchemaMigration.where(version: initial_migration_version).exists?
|
||||
last_squashed_migration_has_run = ActiveRecord::SchemaMigration.where(version: last_squashed_migration_version).exists?
|
|
@ -133,8 +133,8 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.boolean "require_authorization_code"
|
||||
t.string "default_time_zone"
|
||||
t.string "external_status", :default => "active"
|
||||
t.integer "storage_quota"
|
||||
t.integer "default_storage_quota"
|
||||
t.integer "storage_quota", :limit => 8
|
||||
t.integer "default_storage_quota", :limit => 8
|
||||
t.boolean "enable_user_notes", :default => false
|
||||
t.string "allowed_services"
|
||||
t.text "turnitin_pledge"
|
||||
|
@ -148,6 +148,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.text "settings"
|
||||
t.string "sis_name"
|
||||
t.string "uuid"
|
||||
t.string "default_locale"
|
||||
end
|
||||
|
||||
add_index "accounts", ["id", "type"], :name => "index_accounts_on_id_and_type"
|
||||
|
@ -157,6 +158,21 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
add_index "accounts", ["sis_source_id"], :name => "index_accounts_on_sis_source_id"
|
||||
add_index "accounts", ["type"], :name => "index_accounts_on_type"
|
||||
|
||||
create_table :alerts do |t|
|
||||
t.integer :context_id, :limit => 8
|
||||
t.string :context_type
|
||||
t.text :recipients
|
||||
t.integer :repetition
|
||||
|
||||
t.timestamps null: true
|
||||
end
|
||||
|
||||
create_table :alert_criteria do |t|
|
||||
t.integer :alert_id, :limit => 8
|
||||
t.string :criterion_type
|
||||
t.float :threshold
|
||||
end
|
||||
|
||||
create_table "assessment_question_bank_users", :force => true do |t|
|
||||
t.integer "assessment_question_bank_id", :limit => 8
|
||||
t.integer "user_id", :limit => 8
|
||||
|
@ -648,6 +664,8 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
|
||||
create_table "conversations" do |t|
|
||||
t.string "private_hash" # for quick lookups so we know whether or not we need to create a new one
|
||||
t.boolean "has_attachments", :default => false, :null => false
|
||||
t.boolean "has_media_objects", :default => false, :null => false
|
||||
end
|
||||
add_index "conversations", ["private_hash"], :unique => true
|
||||
|
||||
|
@ -658,6 +676,10 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.boolean "subscribed", :default => true
|
||||
t.string "workflow_state"
|
||||
t.datetime "last_authored_at"
|
||||
t.boolean "has_attachments", :default => false, :null => false
|
||||
t.boolean "has_media_objects", :default => false, :null => false
|
||||
t.integer "message_count", :default => 0
|
||||
t.string "label"
|
||||
end
|
||||
add_index "conversation_participants", ["conversation_id"]
|
||||
add_index "conversation_participants", ["user_id", "last_message_at"]
|
||||
|
@ -668,6 +690,10 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.datetime "created_at"
|
||||
t.boolean "generated"
|
||||
t.text "body"
|
||||
t.text "forwarded_message_ids"
|
||||
t.string "media_comment_id"
|
||||
t.string "media_comment_type"
|
||||
t.integer "context_message_id", :limit => 8
|
||||
end
|
||||
add_index "conversation_messages", ["conversation_id", "created_at"]
|
||||
|
||||
|
@ -675,6 +701,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.integer "conversation_message_id", :limit => 8
|
||||
t.integer "conversation_participant_id", :limit => 8
|
||||
end
|
||||
add_index :conversation_message_participants, [:conversation_participant_id, :conversation_message_id], :name => :index_cmp_on_cpi_and_cmi
|
||||
|
||||
create_table "course_account_associations", :force => true do |t|
|
||||
t.integer "course_id", :limit => 8
|
||||
|
@ -724,6 +751,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.boolean "restrict_enrollments_to_section_dates"
|
||||
t.integer "account_id", :limit => 8
|
||||
t.integer "nonxlist_course_id", :limit => 8
|
||||
t.boolean "sticky_xlist"
|
||||
end
|
||||
|
||||
add_index "course_sections", ["course_id"], :name => "index_course_sections_on_course_id"
|
||||
|
@ -766,7 +794,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.string "sis_batch_id"
|
||||
t.boolean "show_all_discussion_entries"
|
||||
t.boolean "open_enrollment"
|
||||
t.integer "storage_quota"
|
||||
t.integer "storage_quota", :limit => 8
|
||||
t.text "tab_configuration"
|
||||
t.boolean "allow_wiki_comments"
|
||||
t.text "turnitin_comments"
|
||||
|
@ -777,6 +805,8 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.string "sis_course_code"
|
||||
t.boolean "restrict_enrollments_to_course_dates"
|
||||
t.integer "template_course_id", :limit => 8
|
||||
t.string "locale"
|
||||
t.text "settings"
|
||||
end
|
||||
|
||||
add_index "courses", ["abstract_course_id"], :name => "index_courses_on_abstract_course_id"
|
||||
|
@ -851,6 +881,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.datetime "updated_at"
|
||||
t.integer "user_id", :limit => 8
|
||||
t.string "name"
|
||||
t.string "redirect_uri"
|
||||
end
|
||||
|
||||
create_table "discussion_entries", :force => true do |t|
|
||||
|
@ -1183,7 +1214,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.string "join_level"
|
||||
t.string "default_view", :default => "feed"
|
||||
t.string "migration_id"
|
||||
t.integer "storage_quota"
|
||||
t.integer "storage_quota", :limit => 8
|
||||
t.string "uuid"
|
||||
t.integer "root_account_id", :limit => 8
|
||||
t.string "sis_source_id"
|
||||
|
@ -1223,6 +1254,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
add_index "inbox_items", ["sender_id"], :name => "index_inbox_items_on_sender_id"
|
||||
add_index "inbox_items", ["user_id"], :name => "index_inbox_items_on_user_id"
|
||||
add_index "inbox_items", ["workflow_state"], :name => "index_inbox_items_on_workflow_state"
|
||||
add_index :inbox_items, [:asset_type, :asset_id]
|
||||
|
||||
create_table "learning_outcome_groups", :force => true do |t|
|
||||
t.integer "context_id", :limit => 8
|
||||
|
@ -1466,6 +1498,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.boolean "participated"
|
||||
t.boolean "summarized"
|
||||
t.integer "account_id", :limit => 8
|
||||
t.integer "real_user_id", :limit => 8
|
||||
end
|
||||
execute("ALTER TABLE #{PageView.quoted_table_name} ADD PRIMARY KEY (request_id)")
|
||||
|
||||
|
@ -1928,6 +1961,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.string "context_code"
|
||||
t.integer "media_object_id", :limit => 8
|
||||
t.text "turnitin_data"
|
||||
t.boolean "has_admin_comment", :default => false, :null => false
|
||||
end
|
||||
|
||||
add_index "submissions", ["assignment_id", "submission_type"], :name => "index_submissions_on_assignment_id_and_submission_type"
|
||||
|
@ -2029,7 +2063,7 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.integer "unread_inbox_items_count"
|
||||
t.integer "reminder_time_for_due_dates", :default => 172800
|
||||
t.integer "reminder_time_for_grading", :default => 0
|
||||
t.integer "storage_quota"
|
||||
t.integer "storage_quota", :limit => 8
|
||||
t.string "visible_inbox_types"
|
||||
t.datetime "last_user_note"
|
||||
t.boolean "subscribe_to_emails"
|
||||
|
@ -2037,6 +2071,9 @@ class InitCanvasDb < ActiveRecord::Migration[4.2]
|
|||
t.string "sis_name"
|
||||
t.text "preferences"
|
||||
t.string "avatar_state"
|
||||
t.string "locale"
|
||||
t.string "browser_locale"
|
||||
t.integer "unread_conversations_count", :default => 0
|
||||
end
|
||||
|
||||
add_index "users", ["avatar_state", "avatar_image_updated_at"], :name => "index_users_on_avatar_state_and_avatar_image_updated_at"
|
||||
|
|
|
@ -52,14 +52,30 @@ class CreateDelayedJobs < ActiveRecord::Migration[4.2]
|
|||
table.string :strand
|
||||
end
|
||||
|
||||
# "nulls first" syntax is postgresql specific, and allows for more
|
||||
# efficient querying for the next job
|
||||
connection.execute("CREATE INDEX get_delayed_jobs_index ON #{Delayed::Backend::ActiveRecord::Job.quoted_table_name} (priority, run_at, failed_at nulls first, locked_at nulls first, queue)")
|
||||
add_index :delayed_jobs, [:tag]
|
||||
add_index :delayed_jobs, :strand
|
||||
add_index :delayed_jobs, %w(run_at queue locked_at strand priority), :name => 'index_delayed_jobs_for_get_next'
|
||||
add_index :delayed_jobs, %w(strand id), :name => 'index_delayed_jobs_on_strand'
|
||||
|
||||
create_table :failed_jobs do |t|
|
||||
t.integer "priority", :default => 0
|
||||
t.integer "attempts", :default => 0
|
||||
t.string "handler", :limit => 512000
|
||||
t.integer "original_id", :limit => 8
|
||||
t.text "last_error"
|
||||
t.string "queue"
|
||||
t.datetime "run_at"
|
||||
t.datetime "locked_at"
|
||||
t.datetime "failed_at"
|
||||
t.string "locked_by"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "tag"
|
||||
t.integer "max_attempts"
|
||||
t.string "strand"
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :delayed_jobs
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 MessageAttachmentsAndMediaObjects < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :conversations, :has_attachments, :boolean
|
||||
add_column :conversations, :has_media_objects, :boolean
|
||||
add_column :conversation_participants, :has_attachments, :boolean
|
||||
add_column :conversation_participants, :has_media_objects, :boolean
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :conversations, :has_attachments
|
||||
remove_column :conversations, :has_media_objects
|
||||
remove_column :conversation_participants, :has_attachments
|
||||
remove_column :conversation_participants, :has_media_objects
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 AddStickyXlisting < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :course_sections, :sticky_xlist, :boolean
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :course_sections, :sticky_xlist
|
||||
end
|
||||
end
|
|
@ -1,59 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 OptimizeDelayedJobs < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.connection
|
||||
Delayed::Backend::ActiveRecord::Job.connection
|
||||
end
|
||||
|
||||
def self.up
|
||||
create_table :failed_jobs do |t|
|
||||
t.integer "priority", :default => 0
|
||||
t.integer "attempts", :default => 0
|
||||
t.string "handler", :limit => 512000
|
||||
t.integer "original_id", :limit => 8
|
||||
t.text "last_error"
|
||||
t.string "queue"
|
||||
t.datetime "run_at"
|
||||
t.datetime "locked_at"
|
||||
t.datetime "failed_at"
|
||||
t.string "locked_by"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "tag"
|
||||
t.integer "max_attempts"
|
||||
t.string "strand"
|
||||
end
|
||||
|
||||
remove_index :delayed_jobs, :name => 'get_delayed_jobs_index'
|
||||
remove_index :delayed_jobs, [:strand]
|
||||
|
||||
add_index :delayed_jobs, %w(run_at queue locked_at strand priority), :name => 'index_delayed_jobs_for_get_next'
|
||||
add_index :delayed_jobs, %w(strand id), :name => 'index_delayed_jobs_on_strand'
|
||||
|
||||
# move all failed jobs to the new failed table
|
||||
Delayed::Backend::ActiveRecord::Job.where("failed_at IS NOT NULL").find_each do |job|
|
||||
job.fail! unless job.on_hold?
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 ConvertStorageQuotasToBytes < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
FIELDS_TO_FIX = [
|
||||
[ User, :storage_quota ],
|
||||
[ Account, :storage_quota ],
|
||||
[ Account, :default_storage_quota ],
|
||||
[ Course, :storage_quota ],
|
||||
[ Group, :storage_quota ],
|
||||
]
|
||||
|
||||
def self.up
|
||||
FIELDS_TO_FIX.each do |klass, field|
|
||||
change_column klass.table_name.to_s, field, :integer, :limit => 8
|
||||
update("UPDATE #{klass.quoted_table_name} SET #{field} = #{field} * 1024 * 1024 WHERE #{field} IS NOT NULL AND #{field} < 1024 * 1024")
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
FIELDS_TO_FIX.each do |klass, field|
|
||||
change_column klass.table_name.to_s, field, :integer, :limit => 4
|
||||
update("UPDATE #{klass.quoted_table_name} SET #{field} = #{field} / 1024 * 1024 WHERE #{field} IS NOT NULL AND #{field} >= 1024 * 1024")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 AddRealUserIdToPageViews < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :page_views, :real_user_id, :integer, :limit => 8
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :page_views, :real_user_id
|
||||
end
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 LocalePrefs < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :users, :locale, :string
|
||||
add_column :users, :browser_locale, :string
|
||||
add_column :courses, :locale, :string
|
||||
add_column :accounts, :default_locale, :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :users, :locale
|
||||
remove_column :users, :browser_locale
|
||||
remove_column :courses, :locale
|
||||
remove_column :accounts, :default_locale
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 CreateAlerts < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
create_table :alerts do |t|
|
||||
t.integer :context_id, :limit => 8
|
||||
t.string :context_type
|
||||
t.text :recipients
|
||||
t.integer :repetition
|
||||
|
||||
t.timestamps null: true
|
||||
end
|
||||
|
||||
create_table :alert_criteria do |t|
|
||||
t.integer :alert_id, :limit => 8
|
||||
t.string :criterion_type
|
||||
t.float :threshold
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :alert_criteria
|
||||
drop_table :alerts
|
||||
end
|
||||
end
|
|
@ -1,39 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 MessageCounts < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :conversation_participants, :message_count, :int, :default => 0
|
||||
update <<-SQL
|
||||
UPDATE #{ConversationParticipant.quoted_table_name}
|
||||
SET message_count = (
|
||||
SELECT COUNT(*)
|
||||
FROM #{ConversationMessage.quoted_table_name}, #{ConversationMessageParticipant.quoted_table_name}
|
||||
WHERE conversation_messages.conversation_id = conversation_participants.conversation_id
|
||||
AND NOT conversation_messages.generated
|
||||
AND conversation_messages.id = conversation_message_participants.conversation_message_id
|
||||
AND conversation_participant_id = conversation_participants.id
|
||||
)
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :conversation_participants, :message_count
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 MessageForwards < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :conversation_messages, :forwarded_message_ids, :text
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :conversation_messages, :forwarded_message_ids
|
||||
end
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 UnreadCounts < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :users, :unread_conversations_count, :int, :default => 0
|
||||
update <<-SQL
|
||||
UPDATE #{User.quoted_table_name}
|
||||
SET unread_conversations_count = (
|
||||
SELECT COUNT(*)
|
||||
FROM #{ConversationParticipant.quoted_table_name}
|
||||
WHERE workflow_state = 'unread'
|
||||
AND last_message_at IS NOT NULL
|
||||
AND user_id = users.id
|
||||
)
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :users, :unread_conversations_count
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 LabelConversations < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :conversation_participants, :label, :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :conversation_participants, :label
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 AddDeveloperKeyRedirectUri < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :developer_keys, :redirect_uri, :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :developer_keys, :redirect_uri
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 FixDuplicateDiscussions < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
DiscussionTopic.transaction do
|
||||
duplicate_topics = DiscussionTopic.
|
||||
select([:old_assignment_id, :context_id, :context_type]).
|
||||
where("old_assignment_id IS NOT NULL AND workflow_state <> 'deleted' AND root_topic_id IS NULL AND context_type='Course'").
|
||||
group('old_assignment_id, context_id, context_type HAVING COUNT(*) > 1').to_a
|
||||
|
||||
duplicate_topics.each do |topic|
|
||||
duplicates = DiscussionTopic.
|
||||
where("context_id=? AND context_type=? AND old_assignment_id=? AND workflow_state<>'deleted' AND root_topic_id is null",
|
||||
topic.context_id, topic.context_type, topic.old_assignment_id).
|
||||
order('updated_at DESC').to_a
|
||||
to_keep = duplicates.shift
|
||||
|
||||
DiscussionEntry.where(:discussion_topic_id => duplicates).update_all(:discussion_topic_id => to_keep)
|
||||
DiscussionTopic.where(:root_topic_id => duplicates).update_all(:root_topic_id => to_keep)
|
||||
DiscussionTopic.delete(duplicates)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 AddSettingsToCourses < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :courses, :settings, :text
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :courses, :settings
|
||||
end
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 ConversationsHasAttachmentsNotNull < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
[:conversations, :conversation_participants].each do |table|
|
||||
[:has_attachments, :has_media_objects].each do |column|
|
||||
change_column_null table, column, false, false
|
||||
change_column_default table, column, false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
[:conversations, :conversation_participants].each do |table|
|
||||
[:has_attachments, :has_media_objects].each do |column|
|
||||
change_column_null table, column, true
|
||||
change_column_default table, column, nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 NewInboxMediaComments < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :conversation_messages, :media_comment_id, :string
|
||||
add_column :conversation_messages, :media_comment_type, :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :conversation_messages, :media_comment_id
|
||||
remove_column :conversation_messages, :media_comment_type
|
||||
end
|
||||
end
|
|
@ -1,307 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 MessageMigration < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_index :conversation_message_participants, [:conversation_participant_id, :conversation_message_id], :name => :index_cmp_on_cpi_and_cmi
|
||||
add_index :inbox_items, [:asset_type, :asset_id]
|
||||
|
||||
# for bringing over attachments and tracking deleted inbox_items
|
||||
# the other new columns get removed at the end of the migration, we'll keep this one for now
|
||||
# in case we need to track/fix any issues post migration
|
||||
add_column :conversation_messages, :context_message_id, :integer, :limit => 8
|
||||
|
||||
return if Rails.env.test?
|
||||
|
||||
unless connection.adapter_name =~ /postgres/
|
||||
$stderr.puts "don't know how to migrate conversation data for #{connection.adapter_name}!"
|
||||
return
|
||||
end
|
||||
|
||||
# for grouping messages into conversations
|
||||
# private: list of participant ids <= 2
|
||||
# group: root_context_message_id + list of participant ids (if the list changes, it's a different conversation)
|
||||
add_column :conversations, :migration_signature, :text
|
||||
|
||||
# helper column for merging into existing private conversations
|
||||
add_column :conversations, :tmp_private_hash, :string
|
||||
|
||||
# from context_message, will get rolled up into conversation_participant
|
||||
add_column :conversation_message_participants, :unread, :boolean
|
||||
|
||||
execute <<-SQL
|
||||
CREATE TEMPORARY TABLE __migrated_messages AS
|
||||
SELECT
|
||||
id,
|
||||
user_id AS author_id,
|
||||
created_at,
|
||||
CASE WHEN subject IS NULL OR LOWER(SUBSTR(subject, 1, 4)) = 're: ' THEN body ELSE subject || #{connection.quote("\n\n")} || body END AS body,
|
||||
COALESCE(root_context_message_id, id) AS root_context_message_id,
|
||||
media_comment_id,
|
||||
media_comment_type,
|
||||
'::TEXT' AS signature
|
||||
FROM
|
||||
#{connection.quote_table_name('context_messages')}
|
||||
SQL
|
||||
execute "CREATE INDEX index__migrated_messages_on_id ON __migrated_messages (id)"
|
||||
|
||||
execute <<-SQL
|
||||
CREATE TEMPORARY TABLE __migrated_message_participants AS
|
||||
SELECT DISTINCT
|
||||
context_message_id AS migrated_message_id,
|
||||
user_id
|
||||
FROM
|
||||
#{connection.quote_table_name('context_message_participants')}
|
||||
SQL
|
||||
execute "CREATE INDEX index_mmp_on_message_id ON __migrated_message_participants (migrated_message_id)"
|
||||
|
||||
execute <<-SQL
|
||||
CREATE TEMPORARY TABLE __migrated_message_participant_strings AS
|
||||
SELECT migrated_message_id, STRING_AGG(user_id::TEXT, ',') AS participants, COUNT(DISTINCT user_id) <= 2 AS private
|
||||
FROM (
|
||||
SELECT DISTINCT migrated_message_id, user_id
|
||||
FROM __migrated_message_participants
|
||||
ORDER BY migrated_message_id, user_id
|
||||
) p
|
||||
GROUP BY migrated_message_id
|
||||
SQL
|
||||
execute "CREATE INDEX index_mmps_on_migrated_message_id ON __migrated_message_participant_strings (migrated_message_id)"
|
||||
|
||||
execute <<-SQL
|
||||
UPDATE __migrated_messages
|
||||
SET signature = CASE WHEN private THEN '' ELSE root_context_message_id || ':' END || participants
|
||||
FROM __migrated_message_participant_strings
|
||||
WHERE migrated_message_id = __migrated_messages.id
|
||||
SQL
|
||||
execute "CREATE INDEX index___migrated_messages_on_signature ON __migrated_messages (signature)"
|
||||
|
||||
execute <<-SQL
|
||||
INSERT INTO #{Conversation.quoted_table_name}(migration_signature, has_attachments, has_media_objects)
|
||||
SELECT DISTINCT signature, FALSE, FALSE
|
||||
FROM __migrated_messages
|
||||
SQL
|
||||
add_index :conversations, :migration_signature
|
||||
|
||||
Conversation.where("migration_signature ~ E'^[0-9]+(,[0-9]+)?$'").find_each(:batch_size => 10000) do |conversation|
|
||||
conversation.update_attribute :tmp_private_hash, Digest::SHA1.hexdigest(conversation.migration_signature)
|
||||
end
|
||||
add_index :conversations, :tmp_private_hash
|
||||
|
||||
# in case any private conversations already exist...
|
||||
update <<-SQL
|
||||
UPDATE #{Conversation.quoted_table_name}
|
||||
SET migration_signature = c2.migration_signature
|
||||
FROM #{Conversation.quoted_table_name} c2
|
||||
WHERE conversations.private_hash = c2.tmp_private_hash
|
||||
SQL
|
||||
execute <<-SQL
|
||||
CREATE TEMPORARY TABLE __existing_private_conversations AS
|
||||
SELECT private_hash FROM #{Conversation.quoted_table_name} WHERE private_hash IS NOT NULL
|
||||
SQL
|
||||
delete <<-SQL
|
||||
DELETE FROM #{Conversation.quoted_table_name} WHERE tmp_private_hash IN (SELECT private_hash FROM __existing_private_conversations)
|
||||
SQL
|
||||
|
||||
# create participants for any group conversations or *new* private conversations
|
||||
remove_index :conversation_participants, :column => [:user_id, :last_message_at]
|
||||
add_index :conversation_participants, :user_id # temporary for better insert speeds (and to prevent people hitting new messaging from killing the db)
|
||||
subquery = "SELECT DISTINCT ON (signature) signature, id FROM __migrated_messages ORDER BY signature, id DESC"
|
||||
execute <<-SQL
|
||||
INSERT INTO #{ConversationParticipant.quoted_table_name}(conversation_id, user_id, subscribed, workflow_state, has_attachments, has_media_objects)
|
||||
SELECT c.id, mp.user_id, TRUE, 'read', FALSE, FALSE
|
||||
FROM __migrated_message_participants mp,
|
||||
(#{subquery}) AS m,
|
||||
#{Conversation.quoted_table_name} c
|
||||
WHERE migrated_message_id = m.id
|
||||
AND migration_signature = signature
|
||||
AND private_hash IS NULL
|
||||
SQL
|
||||
# make sure new private conversations have their hash set
|
||||
update <<-SQL
|
||||
UPDATE #{Conversation.quoted_table_name}
|
||||
SET private_hash = tmp_private_hash
|
||||
WHERE tmp_private_hash IS NOT NULL
|
||||
SQL
|
||||
|
||||
execute <<-SQL
|
||||
INSERT INTO #{ConversationMessage.quoted_table_name}(conversation_id, author_id, created_at, generated, body, media_comment_id, media_comment_type, context_message_id)
|
||||
SELECT
|
||||
conversations.id,
|
||||
author_id,
|
||||
created_at,
|
||||
FALSE,
|
||||
body,
|
||||
media_comment_id,
|
||||
media_comment_type,
|
||||
__migrated_messages.id
|
||||
FROM
|
||||
__migrated_messages, #{Conversation.quoted_table_name}
|
||||
WHERE
|
||||
signature = migration_signature
|
||||
SQL
|
||||
|
||||
|
||||
# make messages visible to users
|
||||
execute <<-SQL
|
||||
INSERT INTO #{ConversationMessageParticipant.quoted_table_name}(conversation_message_id, conversation_participant_id, unread)
|
||||
SELECT
|
||||
cm.id,
|
||||
cp.id,
|
||||
ii.workflow_state = 'unread'
|
||||
FROM
|
||||
#{ConversationMessage.quoted_table_name} cm,
|
||||
#{ConversationParticipant.quoted_table_name} cp,
|
||||
#{connection.quote_table_name('inbox_items')} ii
|
||||
WHERE
|
||||
cm.conversation_id = cp.conversation_id
|
||||
AND ii.asset_id = cm.context_message_id
|
||||
AND ii.asset_type = 'ContextMessage'
|
||||
AND ii.user_id = cp.user_id
|
||||
AND ii.workflow_state <> 'deleted'
|
||||
SQL
|
||||
|
||||
# make sure senders can see their sent items (they don't normally get an inbox_item, unless explicitly added as a recipient)
|
||||
execute <<-SQL
|
||||
INSERT INTO #{ConversationMessageParticipant.quoted_table_name}(conversation_message_id, conversation_participant_id, unread)
|
||||
SELECT
|
||||
cm.id,
|
||||
cp.id,
|
||||
FALSE
|
||||
FROM
|
||||
#{ConversationMessage.quoted_table_name} cm
|
||||
INNER JOIN
|
||||
#{ConversationParticipant.quoted_table_name} cp ON cm.conversation_id = cp.conversation_id AND cm.author_id = cp.user_id
|
||||
LEFT JOIN
|
||||
#{ConversationMessageParticipant.quoted_table_name} existing ON existing.conversation_message_id = cm.id AND existing.conversation_participant_id = cp.id
|
||||
WHERE
|
||||
cm.context_message_id IS NOT NULL
|
||||
AND existing.id IS NULL
|
||||
SQL
|
||||
|
||||
# hide inbox_items from the users
|
||||
update "UPDATE #{connection.quote_table_name('inbox_items')} SET workflow_state = 'retired' WHERE asset_type IN ('ContextMessage', 'SubmissionComment') AND workflow_state = 'read'"
|
||||
update "UPDATE #{connection.quote_table_name('inbox_items')} SET workflow_state = 'retired_unread' WHERE asset_type IN ('ContextMessage', 'SubmissionComment') AND workflow_state = 'unread'"
|
||||
|
||||
|
||||
update <<-SQL
|
||||
UPDATE #{ConversationParticipant.quoted_table_name}
|
||||
SET workflow_state = 'unread'
|
||||
WHERE EXISTS (SELECT 1 FROM #{ConversationMessageParticipant.quoted_table_name} WHERE conversation_participants.id = conversation_participant_id AND unread LIMIT 1)
|
||||
SQL
|
||||
|
||||
|
||||
# attachments
|
||||
update <<-SQL
|
||||
UPDATE #{Attachment.quoted_table_name}
|
||||
SET context_id = conversation_messages.id, context_type = 'ConversationMessage'
|
||||
FROM #{ConversationMessage.quoted_table_name}
|
||||
WHERE attachments.context_type = 'ContextMessage' AND conversation_messages.context_message_id = attachments.context_id
|
||||
SQL
|
||||
|
||||
update <<-SQL
|
||||
UPDATE #{ConversationParticipant.quoted_table_name}
|
||||
SET has_attachments = TRUE
|
||||
WHERE id IN (
|
||||
SELECT conversation_participant_id
|
||||
FROM #{ConversationMessageParticipant.quoted_table_name} cmp, #{Attachment.quoted_table_name} a
|
||||
WHERE
|
||||
a.context_type = 'ConversationMessage'
|
||||
AND a.context_id = conversation_message_id
|
||||
)
|
||||
SQL
|
||||
|
||||
update <<-SQL
|
||||
UPDATE #{Conversation.quoted_table_name}
|
||||
SET has_attachments = TRUE
|
||||
WHERE id IN (
|
||||
SELECT conversation_id
|
||||
FROM #{ConversationMessage.quoted_table_name} cm, #{Attachment.quoted_table_name} a
|
||||
WHERE
|
||||
a.context_type = 'ConversationMessage'
|
||||
AND a.context_id = cm.id
|
||||
)
|
||||
SQL
|
||||
|
||||
|
||||
# audio comments
|
||||
update <<-SQL
|
||||
UPDATE #{ConversationParticipant.quoted_table_name}
|
||||
SET has_media_objects = TRUE
|
||||
WHERE id IN (
|
||||
SELECT conversation_participant_id
|
||||
FROM #{ConversationMessageParticipant.quoted_table_name} cmp, #{ConversationMessage.quoted_table_name} cm
|
||||
WHERE cmp.conversation_message_id = cm.id AND media_comment_id IS NOT NULL
|
||||
)
|
||||
SQL
|
||||
|
||||
update <<-SQL
|
||||
UPDATE #{Conversation.quoted_table_name}
|
||||
SET has_media_objects = TRUE
|
||||
WHERE id IN (
|
||||
SELECT conversation_id
|
||||
FROM #{ConversationMessage.quoted_table_name}
|
||||
WHERE media_comment_id IS NOT NULL
|
||||
)
|
||||
SQL
|
||||
|
||||
# cached stats
|
||||
execute <<-SQL
|
||||
CREATE TEMPORARY TABLE __migrated_conversation_stats AS
|
||||
SELECT
|
||||
conversation_participant_id,
|
||||
COUNT(*) AS message_count,
|
||||
MAX(cm.created_at) AS last_message_at,
|
||||
MAX(CASE WHEN cm.author_id = cp.user_id THEN cm.created_at ELSE NULL END) AS last_authored_at
|
||||
FROM #{ConversationMessageParticipant.quoted_table_name} cmp, #{ConversationMessage.quoted_table_name} cm, #{ConversationParticipant.quoted_table_name} cp
|
||||
WHERE conversation_message_id = cm.id AND conversation_participant_id = cp.id
|
||||
GROUP BY conversation_participant_id
|
||||
SQL
|
||||
execute "CREATE INDEX index_mcs_on_cpi ON __migrated_conversation_stats (conversation_participant_id)"
|
||||
|
||||
update <<-SQL
|
||||
UPDATE #{ConversationParticipant.quoted_table_name}
|
||||
SET message_count = __migrated_conversation_stats.message_count,
|
||||
last_message_at = __migrated_conversation_stats.last_message_at,
|
||||
last_authored_at = __migrated_conversation_stats.last_authored_at
|
||||
'FROM __migrated_conversation_stats'
|
||||
WHERE conversation_participants.id = conversation_participant_id
|
||||
SQL
|
||||
add_index :conversation_participants, [:user_id, :last_message_at]
|
||||
remove_index :conversation_participants, :column => :user_id
|
||||
|
||||
execute <<-SQL
|
||||
UPDATE #{User.quoted_table_name}
|
||||
SET unread_conversations_count = (SELECT COUNT(*) FROM #{ConversationParticipant.quoted_table_name} WHERE workflow_state = 'unread' AND user_id = users.id)
|
||||
SQL
|
||||
|
||||
remove_column :conversations, :migration_signature
|
||||
remove_column :conversations, :tmp_private_hash
|
||||
remove_column :conversation_message_participants, :unread
|
||||
|
||||
execute "DROP TABLE __migrated_messages"
|
||||
execute "DROP TABLE __migrated_message_participants"
|
||||
execute "DROP TABLE __migrated_message_participant_strings"
|
||||
execute "DROP TABLE __existing_private_conversations"
|
||||
execute "DROP TABLE __migrated_conversation_stats"
|
||||
end
|
||||
|
||||
def self.down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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 SubmissionHasAdminComment < ActiveRecord::Migration[4.2]
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :submissions, :has_admin_comment, :boolean, :default => false, :null => false
|
||||
update <<-SQL
|
||||
UPDATE #{Submission.quoted_table_name} SET has_admin_comment=EXISTS(
|
||||
SELECT 1 FROM #{SubmissionComment.quoted_table_name} AS sc, #{Assignment.quoted_table_name} AS a, #{Course.quoted_table_name} AS c, #{Enrollment.quoted_table_name} AS e
|
||||
WHERE sc.submission_id=submissions.id AND a.id = submissions.assignment_id
|
||||
AND submissions.workflow_state <> 'deleted'
|
||||
AND c.id = a.context_id AND a.context_type = 'Course' AND e.course_id = c.id
|
||||
AND e.user_id = sc.author_id AND e.workflow_state = 'active'
|
||||
AND e.type IN ('TeacherEnrollment', 'TaEnrollment'))
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :submissions, :has_admin_comment
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue