Skip to content

Commit 920a6bf

Browse files
committed
fix mysql problems with boolean cast and temp tables
refs CNVS-7032 * mysql doesn't have boolean * mysql will auto-commit the transaction unless you explicitly say TEMPORARY when dropping the temp table Change-Id: Iaca3ddd5768f509a0b610925f601e1712e9b7d42 Reviewed-on: https://gerrit.instructure.com/22666 Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com>
1 parent d230897 commit 920a6bf

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

lib/canvas/temp_table.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def execute_frd
4242

4343
yield self
4444
ensure
45-
@connection.execute "DROP TABLE #{@name}"
45+
temporary = "TEMPORARY " if @connection.adapter_name == 'Mysql2'
46+
@connection.execute "DROP #{temporary}TABLE #{@name}"
4647
end
4748
end
4849

lib/due_date_cacher.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ def recompute
2929
shard.activate do
3030
Assignment.transaction do
3131
# create temporary table
32+
cast = Submission.connection.adapter_name == 'Mysql2' ? 'UNSIGNED INTEGER' : 'BOOL'
3233
Assignment.connection.execute("CREATE TEMPORARY TABLE calculated_due_ats AS (#{submissions.select([
3334
"submissions.id AS submission_id",
3435
"submissions.user_id",
3536
"submissions.assignment_id",
3637
"assignments.due_at",
37-
"CAST(#{Submission.sanitize(false)} AS BOOL) AS overridden"
38+
"CAST(#{Submission.sanitize(false)} AS #{cast}) AS overridden"
3839
]).joins(:assignment).to_sql})")
3940

4041
# create an ActiveRecord class around that temp table for the update_all
@@ -57,7 +58,8 @@ def recompute
5758
update_all("cached_due_date=calculated_due_ats.due_at")
5859

5960
# clean up
60-
Assignment.connection.execute("DROP TABLE calculated_due_ats")
61+
temporary = "TEMPORARY " if Assignment.connection.adapter_name == 'Mysql2'
62+
Assignment.connection.execute("DROP #{temporary}TABLE calculated_due_ats")
6163
end
6264
end
6365
end

0 commit comments

Comments
 (0)