Skip to content

Commit d236166

Browse files
committed
drop mysql support and gem
test plan - specs should pass Change-Id: Ib3f102b53d947198625e3118820d22e77a005dd6 Reviewed-on: https://gerrit.instructure.com/77249 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins Product-Review: Rob Orton <rob@instructure.com> QA-Review: Rob Orton <rob@instructure.com>
1 parent 91f7e73 commit d236166

37 files changed

Lines changed: 118 additions & 397 deletions

File tree

Gemfile.d/mysql.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/models/page_view.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def to_row(format = nil)
382382
export_columns(format).map { |c| self.send(c).presence }
383383
end
384384

385-
# utility class to migrate a postgresql/mysql/sqlite3 page_views table to cassandra
385+
# utility class to migrate a postgresql/sqlite3 page_views table to cassandra
386386
class CassandraMigrator < Struct.new(:start_at, :logger, :migration_data)
387387
# if you interrupt and re-start the migrator, start_at cannot be changed,
388388
# since it's saved in cassandra to persist the migration state

app/models/pseudonym.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ def send_confirmation!
138138
}
139139

140140
def self.to_lower_column(column)
141-
if %w{mysql mysql2}.include?(connection_pool.spec.config[:adapter])
142-
column
143-
else
144-
"LOWER(#{column})"
145-
end
141+
"LOWER(#{column})"
146142
end
147143

148144
def self.custom_find_by_unique_id(unique_id)

app/models/quizzes/quiz.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,6 @@ def update_quiz_submission_end_at_times
428428
update_sql = case ActiveRecord::Base.connection.adapter_name
429429
when 'PostgreSQL'
430430
"started_at + INTERVAL '+? seconds'"
431-
when 'MySQL', 'Mysql2'
432-
"started_at + INTERVAL ? SECOND"
433431
when /sqlite/
434432
"DATETIME(started_at, '+? seconds')"
435433
end

config/initializers/active_record.rb

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,6 @@ def self.count_by_date(options = {})
389389
offset = max_date.utc_offset
390390

391391
expression = case connection.adapter_name
392-
when 'MySQL', 'Mysql2'
393-
# TODO: detect mysql named timezone support and use it
394-
offset = "%s%02d:%02d" % [offset < 0 ? "-" : "+", offset.abs / 3600, offset.abs % 3600]
395-
"DATE(CONVERT_TZ(#{column}, '+00:00', '#{offset}'))"
396392
when /sqlite/
397393
"DATE(STRFTIME('%s', #{column}) + #{offset}, 'unixepoch')"
398394
when 'PostgreSQL'
@@ -773,10 +769,6 @@ def find_in_batches_with_temp_table(options = {})
773769
ensure
774770
connection.raw_connection.set_notice_processor(&old_proc) if old_proc
775771
end
776-
when 'MySQL', 'Mysql2'
777-
pluck.unshift(index) if pluck
778-
connection.execute "ALTER TABLE #{table}
779-
ADD temp_primary_key MEDIUMINT NOT NULL PRIMARY KEY AUTO_INCREMENT"
780772
when 'SQLite'
781773
# Sqlite always has an implicit primary key
782774
index = 'rowid'
@@ -820,8 +812,7 @@ def find_in_batches_with_temp_table(options = {})
820812
end
821813
ensure
822814
unless $!.is_a?(ActiveRecord::StatementInvalid)
823-
temporary = "TEMPORARY " if connection.adapter_name == 'Mysql2'
824-
connection.execute "DROP #{temporary}TABLE #{table}"
815+
connection.execute "DROP TABLE #{table}"
825816
end
826817
end
827818
end
@@ -1012,8 +1003,6 @@ def delete_all(conditions = nil, *args)
10121003
end
10131004
sql.concat('WHERE ' + sql_string.compile(binds.map{|bvs| connection.quote(*bvs.reverse)}))
10141005
end
1015-
when 'MySQL', 'Mysql2'
1016-
sql = "DELETE #{quoted_table_name} FROM #{quoted_table_name} #{arel.join_sql} #{arel.where_sql}"
10171006
else
10181007
raise "Joins in delete not supported!"
10191008
end
@@ -1103,57 +1092,6 @@ def infer_group_by_columns(columns)
11031092
end
11041093
end
11051094

1106-
module MySQLAdapterExtensions
1107-
def self.included(klass)
1108-
klass::NATIVE_DATABASE_TYPES[:primary_key] = "bigint DEFAULT NULL auto_increment PRIMARY KEY".freeze
1109-
klass.alias_method_chain :configure_connection, :pg_compat
1110-
end
1111-
1112-
def rename_index(table_name, old_name, new_name)
1113-
if version[0] >= 5 && version[1] >= 7
1114-
return execute "ALTER TABLE #{quote_table_name(table_name)} RENAME INDEX #{quote_column_name(old_name)} TO #{quote_table_name(new_name)}";
1115-
else
1116-
old_index_def = indexes(table_name).detect { |i| i.name == old_name }
1117-
return unless old_index_def
1118-
add_index(table_name, old_index_def.columns, :name => new_name, :unique => old_index_def.unique)
1119-
remove_index(table_name, :name => old_name)
1120-
end
1121-
end
1122-
1123-
def bulk_insert(table_name, records)
1124-
keys = records.first.keys
1125-
quoted_keys = keys.map{ |k| quote_column_name(k) }.join(', ')
1126-
execute "INSERT INTO #{quote_table_name(table_name)} (#{quoted_keys}) VALUES" <<
1127-
records.map{ |record| "(#{keys.map{ |k| quote(record[k]) }.join(', ')})" }.join(',')
1128-
end
1129-
1130-
def add_column_with_foreign_key_check(table, name, type, options = {})
1131-
Canvas.active_record_foreign_key_check(name, type, options) unless adapter_name == 'Sqlite'
1132-
add_column_without_foreign_key_check(table, name, type, options)
1133-
end
1134-
1135-
def configure_connection_with_pg_compat
1136-
configure_connection_without_pg_compat
1137-
execute "SET SESSION SQL_MODE='PIPES_AS_CONCAT'"
1138-
end
1139-
1140-
def func(name, *args)
1141-
case name
1142-
when :group_concat
1143-
"group_concat(#{func_arg_esc(args.first)} SEPARATOR #{quote(args[1] || ',')})"
1144-
else
1145-
super
1146-
end
1147-
end
1148-
end
1149-
1150-
if defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
1151-
ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:include, MySQLAdapterExtensions)
1152-
end
1153-
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
1154-
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send(:include, MySQLAdapterExtensions)
1155-
end
1156-
11571095
ActiveRecord::Associations::HasOneAssociation.class_eval do
11581096
def create_scope
11591097
scope = self.scope.scope_for_create.stringify_keys
@@ -1330,7 +1268,7 @@ def remove_foreign_key_if_exists(table, options = {})
13301268
begin
13311269
remove_foreign_key(table, options)
13321270
rescue ActiveRecord::StatementInvalid => e
1333-
raise unless e.message =~ /PG(?:::)?Error: ERROR:.+does not exist|Mysql2?::Error: Error on rename/
1271+
raise unless e.message =~ /PG(?:::)?Error: ERROR:.+does not exist/
13341272
end
13351273
end
13361274

db/migrate/20110816203511_message_migration.rb

Lines changed: 38 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ def self.up
1212

1313
return if Rails.env.test?
1414

15-
unless connection.adapter_name =~ /postgres|mysql/i
15+
unless connection.adapter_name =~ /postgres/
1616
$stderr.puts "don't know how to migrate conversation data for #{connection.adapter_name}!"
1717
return
1818
end
1919

20-
mysql = %w{MySQL Mysql2}.include?(connection.adapter_name)
21-
table_opts = mysql ? 'engine=innodb' : 'AS'
22-
2320
# for grouping messages into conversations
2421
# private: list of participant ids <= 2
2522
# group: root_context_message_id + list of participant ids (if the list changes, it's a different conversation)
@@ -32,7 +29,7 @@ def self.up
3229
add_column :conversation_message_participants, :unread, :boolean
3330

3431
execute <<-SQL
35-
CREATE TEMPORARY TABLE __migrated_messages #{table_opts}
32+
CREATE TEMPORARY TABLE __migrated_messages AS
3633
SELECT
3734
id,
3835
user_id AS author_id,
@@ -41,15 +38,14 @@ def self.up
4138
COALESCE(root_context_message_id, id) AS root_context_message_id,
4239
media_comment_id,
4340
media_comment_type,
44-
''#{mysql ? '' : '::TEXT'} AS signature
41+
'::TEXT' AS signature
4542
FROM
4643
#{connection.quote_table_name('context_messages')}
4744
SQL
48-
change_column :__migrated_messages, :signature, :text if mysql
4945
execute "CREATE INDEX index__migrated_messages_on_id ON __migrated_messages (id)"
5046

5147
execute <<-SQL
52-
CREATE TEMPORARY TABLE __migrated_message_participants #{table_opts}
48+
CREATE TEMPORARY TABLE __migrated_message_participants AS
5349
SELECT DISTINCT
5450
context_message_id AS migrated_message_id,
5551
user_id
@@ -58,72 +54,47 @@ def self.up
5854
SQL
5955
execute "CREATE INDEX index_mmp_on_message_id ON __migrated_message_participants (migrated_message_id)"
6056

61-
if mysql
62-
execute <<-SQL
63-
CREATE TEMPORARY TABLE __migrated_message_participant_strings #{table_opts}
64-
SELECT migrated_message_id, GROUP_CONCAT(DISTINCT user_id ORDER BY user_id) AS participants, COUNT(DISTINCT user_id) <= 2 AS private
57+
execute <<-SQL
58+
CREATE TEMPORARY TABLE __migrated_message_participant_strings AS
59+
SELECT migrated_message_id, STRING_AGG(user_id::TEXT, ',') AS participants, COUNT(DISTINCT user_id) <= 2 AS private
60+
FROM (
61+
SELECT DISTINCT migrated_message_id, user_id
6562
FROM __migrated_message_participants
66-
GROUP BY migrated_message_id
67-
SQL
68-
else
69-
execute <<-SQL
70-
CREATE TEMPORARY TABLE __migrated_message_participant_strings #{table_opts}
71-
SELECT migrated_message_id, STRING_AGG(user_id::TEXT, ',') AS participants, COUNT(DISTINCT user_id) <= 2 AS private
72-
FROM (
73-
SELECT DISTINCT migrated_message_id, user_id
74-
FROM __migrated_message_participants
75-
ORDER BY migrated_message_id, user_id
76-
) p
77-
GROUP BY migrated_message_id
78-
SQL
79-
end
63+
ORDER BY migrated_message_id, user_id
64+
) p
65+
GROUP BY migrated_message_id
66+
SQL
8067
execute "CREATE INDEX index_mmps_on_migrated_message_id ON __migrated_message_participant_strings (migrated_message_id)"
8168

8269
execute <<-SQL
83-
UPDATE __migrated_messages #{mysql ? ", __migrated_message_participant_strings" : ""}
70+
UPDATE __migrated_messages
8471
SET signature = CASE WHEN private THEN '' ELSE root_context_message_id || ':' END || participants
85-
#{mysql ? "" : " FROM __migrated_message_participant_strings"}
72+
FROM __migrated_message_participant_strings
8673
WHERE migrated_message_id = __migrated_messages.id
8774
SQL
88-
if mysql
89-
execute "CREATE INDEX index___migrated_messages_on_signature ON __migrated_messages (signature(767))"
90-
else
91-
execute "CREATE INDEX index___migrated_messages_on_signature ON __migrated_messages (signature)"
92-
end
75+
execute "CREATE INDEX index___migrated_messages_on_signature ON __migrated_messages (signature)"
9376

9477
execute <<-SQL
9578
INSERT INTO #{Conversation.quoted_table_name}(migration_signature, has_attachments, has_media_objects)
9679
SELECT DISTINCT signature, FALSE, FALSE
9780
FROM __migrated_messages
9881
SQL
99-
if mysql
100-
execute "CREATE INDEX index_conversations_on_migration_signature ON conversations (migration_signature(767))"
101-
else
102-
add_index :conversations, :migration_signature
103-
end
82+
add_index :conversations, :migration_signature
10483

105-
if mysql
106-
update <<-SQL
107-
UPDATE #{Conversation.quoted_table_name}
108-
SET tmp_private_hash = SHA(migration_signature)
109-
WHERE migration_signature REGEXP '^[0-9]+(,[0-9]+)?$'
110-
SQL
111-
else
112-
Conversation.where("migration_signature ~ E'^[0-9]+(,[0-9]+)?$'").find_each(:batch_size => 10000) do |conversation|
113-
conversation.update_attribute :tmp_private_hash, Digest::SHA1.hexdigest(conversation.migration_signature)
114-
end
84+
Conversation.where("migration_signature ~ E'^[0-9]+(,[0-9]+)?$'").find_each(:batch_size => 10000) do |conversation|
85+
conversation.update_attribute :tmp_private_hash, Digest::SHA1.hexdigest(conversation.migration_signature)
11586
end
11687
add_index :conversations, :tmp_private_hash
11788

11889
# in case any private conversations already exist...
11990
update <<-SQL
120-
UPDATE #{Conversation.quoted_table_name} #{mysql ? ", #{Conversation.quoted_table_name} c2" : ""}
121-
SET #{mysql ? "conversations." : ""}migration_signature = c2.migration_signature
122-
#{mysql ? "" : " FROM #{Conversation.quoted_table_name} c2"}
91+
UPDATE #{Conversation.quoted_table_name}
92+
SET migration_signature = c2.migration_signature
93+
FROM #{Conversation.quoted_table_name} c2
12394
WHERE conversations.private_hash = c2.tmp_private_hash
12495
SQL
12596
execute <<-SQL
126-
CREATE TEMPORARY TABLE __existing_private_conversations #{table_opts}
97+
CREATE TEMPORARY TABLE __existing_private_conversations AS
12798
SELECT private_hash FROM #{Conversation.quoted_table_name} WHERE private_hash IS NOT NULL
12899
SQL
129100
delete <<-SQL
@@ -133,9 +104,7 @@ def self.up
133104
# create participants for any group conversations or *new* private conversations
134105
remove_index :conversation_participants, :column => [:user_id, :last_message_at]
135106
add_index :conversation_participants, :user_id # temporary for better insert speeds (and to prevent people hitting new messaging from killing the db)
136-
subquery = mysql ?
137-
"SELECT signature, id FROM __migrated_messages GROUP BY signature ORDER BY signature, id DESC" :
138-
"SELECT DISTINCT ON (signature) signature, id FROM __migrated_messages ORDER BY signature, id DESC"
107+
subquery = "SELECT DISTINCT ON (signature) signature, id FROM __migrated_messages ORDER BY signature, id DESC"
139108
execute <<-SQL
140109
INSERT INTO #{ConversationParticipant.quoted_table_name}(conversation_id, user_id, subscribed, workflow_state, has_attachments, has_media_objects)
141110
SELECT c.id, mp.user_id, TRUE, 'read', FALSE, FALSE
@@ -222,9 +191,9 @@ def self.up
222191

223192
# attachments
224193
update <<-SQL
225-
UPDATE #{Attachment.quoted_table_name} #{mysql ? ', conversation_messages' : ''}
194+
UPDATE #{Attachment.quoted_table_name}
226195
SET context_id = conversation_messages.id, context_type = 'ConversationMessage'
227-
#{mysql ? '' : "FROM #{ConversationMessage.quoted_table_name}"}
196+
FROM #{ConversationMessage.quoted_table_name}
228197
WHERE attachments.context_type = 'ContextMessage' AND conversation_messages.context_message_id = attachments.context_id
229198
SQL
230199

@@ -276,7 +245,7 @@ def self.up
276245

277246
# cached stats
278247
execute <<-SQL
279-
CREATE TEMPORARY TABLE __migrated_conversation_stats #{table_opts}
248+
CREATE TEMPORARY TABLE __migrated_conversation_stats AS
280249
SELECT
281250
conversation_participant_id,
282251
COUNT(*) AS message_count,
@@ -289,36 +258,20 @@ def self.up
289258
execute "CREATE INDEX index_mcs_on_cpi ON __migrated_conversation_stats (conversation_participant_id)"
290259

291260
update <<-SQL
292-
UPDATE #{ConversationParticipant.quoted_table_name} #{mysql ? ', __migrated_conversation_stats' : ''}
293-
SET #{mysql ? 'conversation_participants.' : ''}message_count = __migrated_conversation_stats.message_count,
294-
#{mysql ? 'conversation_participants.' : ''}last_message_at = __migrated_conversation_stats.last_message_at,
295-
#{mysql ? 'conversation_participants.' : ''}last_authored_at = __migrated_conversation_stats.last_authored_at
296-
#{mysql ? '' : 'FROM __migrated_conversation_stats'}
261+
UPDATE #{ConversationParticipant.quoted_table_name}
262+
SET message_count = __migrated_conversation_stats.message_count,
263+
last_message_at = __migrated_conversation_stats.last_message_at,
264+
last_authored_at = __migrated_conversation_stats.last_authored_at
265+
'FROM __migrated_conversation_stats'
297266
WHERE conversation_participants.id = conversation_participant_id
298267
SQL
299-
if mysql
300-
execute <<-SQL
301-
ALTER TABLE #{ConversationParticipant.quoted_table_name}
302-
ADD INDEX index_conversation_participants_on_user_id_and_last_message_at (user_id, last_message_at),
303-
DROP INDEX index_conversation_participants_on_user_id
304-
SQL
305-
else
306-
add_index :conversation_participants, [:user_id, :last_message_at]
307-
remove_index :conversation_participants, :column => :user_id
308-
end
268+
add_index :conversation_participants, [:user_id, :last_message_at]
269+
remove_index :conversation_participants, :column => :user_id
309270

310-
if mysql
311-
update <<-SQL
312-
UPDATE #{User.quoted_table_name}, (SELECT COUNT(*) AS unread_count, user_id FROM #{ConversationParticipant.quoted_table_name} WHERE workflow_state = 'unread' GROUP BY user_id) AS counts
313-
SET unread_conversations_count = unread_count
314-
WHERE user_id = users.id
315-
SQL
316-
else
317-
execute <<-SQL
318-
UPDATE #{User.quoted_table_name}
319-
SET unread_conversations_count = (SELECT COUNT(*) FROM #{ConversationParticipant.quoted_table_name} WHERE workflow_state = 'unread' AND user_id = users.id)
320-
SQL
321-
end
271+
execute <<-SQL
272+
UPDATE #{User.quoted_table_name}
273+
SET unread_conversations_count = (SELECT COUNT(*) FROM #{ConversationParticipant.quoted_table_name} WHERE workflow_state = 'unread' AND user_id = users.id)
274+
SQL
322275

323276
remove_column :conversations, :migration_signature
324277
remove_column :conversations, :tmp_private_hash

db/migrate/20110825214829_question_data_length.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

db/migrate/20111010205553_drop_deleted_unique_id_from_pseudonyms.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ def self.up
99
def self.down
1010
add_column :pseudonyms, :deleted_unique_id, :string
1111
Pseudonym.where("unique_id IS NOT NULL AND workflow_state='deleted'").update_all('deleted_unique_id=unique_id')
12-
if %w{MySQL Mysql2}.include?(Pseudonym.connection.adapter_name)
13-
Pseudonym.where("unique_id IS NOT NULL AND workflow_state='deleted'").update_all("unique_id=unique_id || '--' || SUBSTR(RAND(), 3, 4)")
14-
else
15-
Pseudonym.where("unique_id IS NOT NULL AND workflow_state='deleted'").update_all("unique_id=unique_id || '--' || SUBSTR(CAST(RANDOM() AS varchar), 3, 4)")
16-
end
12+
Pseudonym.where("unique_id IS NOT NULL AND workflow_state='deleted'").update_all("unique_id=unique_id || '--' || SUBSTR(CAST(RANDOM() AS varchar), 3, 4)")
1713
end
1814
end

0 commit comments

Comments
 (0)