Created
December 21, 2011 23:58
-
-
Save rafaelsachetto/1508285 to your computer and use it in GitHub Desktop.
monkey path to support 18.446.744.073.709.551.615 records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:primary_key] = "BIGINT UNSIGNED DEFAULT NULL auto_increment PRIMARY KEY" | |
ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:reference] = "BIGINT UNSIGNED" | |
class ActiveRecord::ConnectionAdapters::TableDefinition | |
%w( string text integer float decimal datetime timestamp time date binary boolean reference ).each do |column_type| | |
class_eval <<-EOV, __FILE__, __LINE__ + 1 | |
def #{column_type}(*args) # def string(*args) | |
options = args.extract_options! # options = args.extract_options! | |
column_names = args # column_names = args | |
type = :'#{column_type}' # type = :string | |
column_names.each { |name| column(name, type, options) } # column_names.each { |name| column(name, type, options) } | |
end # end | |
EOV | |
end | |
def references(*args) | |
options = args.extract_options! | |
polymorphic = options.delete(:polymorphic) | |
args.each do |col| | |
column("#{col}_id", :reference, options) | |
column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) unless polymorphic.nil? | |
end | |
end | |
class Table | |
def references(*args) | |
options = args.extract_options! | |
polymorphic = options.delete(:polymorphic) | |
args.each do |col| | |
@base.add_column(@table_name, "#{col}_id", :reference, options) | |
@base.add_column(@table_name, "#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) unless polymorphic.nil? | |
end | |
end | |
%w( string text integer float decimal datetime timestamp time date binary boolean reference ).each do |column_type| | |
class_eval <<-EOV, __FILE__, __LINE__ + 1 | |
def #{column_type}(*args) # def string(*args) | |
options = args.extract_options! # options = args.extract_options! | |
column_names = args # column_names = args | |
type = :'#{column_type}' # type = :string | |
column_names.each do |name| # column_names.each do |name| | |
column = ColumnDefinition.new(@base, name.to_s, type) # column = ColumnDefinition.new(@base, name, type) | |
if options[:limit] # if options[:limit] | |
column.limit = options[:limit] # column.limit = options[:limit] | |
elsif native[type].is_a?(Hash) # elsif native[type].is_a?(Hash) | |
column.limit = native[type][:limit] # column.limit = native[type][:limit] | |
end # end | |
column.precision = options[:precision] # column.precision = options[:precision] | |
column.scale = options[:scale] # column.scale = options[:scale] | |
column.default = options[:default] # column.default = options[:default] | |
column.null = options[:null] # column.null = options[:null] | |
@base.add_column(@table_name, name, column.sql_type, options) # @base.add_column(@table_name, name, column.sql_type, options) | |
end # end | |
end # end | |
EOV | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment