clean up temporary tables in migrations

since an external connection pool might be in use, and it would mess
up future migrations

test plan:
 * create two new shards through pgbouncer in the same database in
   quick succession

Change-Id: I2bf582a543a48f9df83888feda54818211931a34
Reviewed-on: https://gerrit.instructure.com/9842
Reviewed-by: Jon Jensen <jon@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
Cody Cutrer 2012-04-04 16:24:53 -06:00
parent 4dae9300fa
commit fad518c082
2 changed files with 7 additions and 0 deletions

View File

@ -321,6 +321,12 @@ class MessageMigration < ActiveRecord::Migration
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

View File

@ -96,6 +96,7 @@ class AddDelayedJobsNextInStrand < ActiveRecord::Migration
# use temp tables to work around subselect limitations in mysql
execute(%{CREATE TEMPORARY TABLE dj_20110831210257 (strand varchar(255), next_job_id bigint) SELECT strand, min(id) as next_job_id FROM delayed_jobs WHERE strand IS NOT NULL GROUP BY strand})
execute(%{UPDATE delayed_jobs SET next_in_strand = #{Delayed::Job.quote_value(false)} WHERE strand IS NOT NULL AND id <> (SELECT t.next_job_id FROM dj_20110831210257 t WHERE t.strand = delayed_jobs.strand)})
execute(%{DROP TABLE dj_20110831210257})
else
execute(%{UPDATE delayed_jobs SET next_in_strand = #{Delayed::Job.quote_value(false)} WHERE strand IS NOT NULL AND id <> (SELECT id FROM delayed_jobs j2 WHERE j2.strand = delayed_jobs.strand ORDER BY j2.strand, j2.id ASC LIMIT 1)})
end