Skip to content

Commit 2224034

Browse files
committed
fix ActiveRecordError refs in bulk_change_table.rb - make it more copy-paste friendly
1 parent bb70a25 commit 2224034

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/arjdbc/mysql/adapter.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module MySQL
1818

1919
include BulkChangeTable if const_defined? :BulkChangeTable
2020

21+
# @private
22+
ActiveRecordError = ::ActiveRecord::ActiveRecordError
23+
2124
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
2225
def self.jdbc_connection_class
2326
::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
@@ -586,7 +589,7 @@ def rename_column(table_name, column_name, new_column_name)
586589
options[:default] = column.default if type != :text && type != :binary
587590
options[:null] = column.null
588591
else
589-
raise ActiveRecord::ActiveRecordError, "No such column: #{table_name}.#{column_name}"
592+
raise ActiveRecordError, "No such column: #{table_name}.#{column_name}"
590593
end
591594

592595
current_type = select_one("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE '#{column_name}'")["Type"]
@@ -662,7 +665,7 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
662665
when 0..0xfff; "varbinary(#{limit})"
663666
when nil; "blob"
664667
when 0x1000..0xffffffff; "blob(#{limit})"
665-
else raise ActiveRecord::ActiveRecordError, "No binary type has character length #{limit}"
668+
else raise ActiveRecordError, "No binary type has character length #{limit}"
666669
end
667670
when 'integer'
668671
case limit
@@ -671,15 +674,15 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
671674
when 3; 'mediumint'
672675
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
673676
when 5..8; 'bigint'
674-
else raise ActiveRecord::ActiveRecordError, "No integer type has byte size #{limit}"
677+
else raise ActiveRecordError, "No integer type has byte size #{limit}"
675678
end
676679
when 'text'
677680
case limit
678681
when 0..0xff; 'tinytext'
679682
when nil, 0x100..0xffff; 'text'
680683
when 0x10000..0xffffff; 'mediumtext'
681684
when 0x1000000..0xffffffff; 'longtext'
682-
else raise ActiveRecord::ActiveRecordError, "No text type has character length #{limit}"
685+
else raise ActiveRecordError, "No text type has character length #{limit}"
683686
end
684687
else
685688
super

lib/arjdbc/mysql/bulk_change_table.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ module MySQL
33
module BulkChangeTable
44

55
# @private
6-
AR41 = ActiveRecord::VERSION::STRING >= '4.1'
6+
AR41 = ::ActiveRecord::VERSION::STRING >= '4.1'
77

88
# @private
9-
ChangeColumnDefinition = ActiveRecord::ConnectionAdapters::ChangeColumnDefinition if AR41
9+
#ActiveRecordError = ActiveRecord::ActiveRecordError
10+
11+
# @private
12+
ChangeColumnDefinition = ::ActiveRecord::ConnectionAdapters::ChangeColumnDefinition if AR41
1013

1114
# @override
1215
def supports_bulk_alter?; true end
@@ -106,12 +109,12 @@ def rename_column_sql(table_name, column_name, new_column_name)
106109
schema_creation.accept ChangeColumnDefinition.new column, current_type, options
107110
end if AR41
108111

109-
def remove_column_sql(table_name, column_name, type = nil, options = {})
112+
def remove_column_sql(table_name, column_name, type = nil, options = nil)
110113
"DROP #{quote_column_name(column_name)}"
111114
end
112115

113116
def remove_columns_sql(table_name, *column_names)
114-
column_names.map {|column_name| remove_column_sql(table_name, column_name) }
117+
column_names.map { |column_name| remove_column_sql(table_name, column_name) }
115118
end
116119

117120
def add_index_sql(table_name, column_name, options = {})

0 commit comments

Comments
 (0)