Skip to content

Instantly share code, notes, and snippets.

@matthuhiggins
Created November 27, 2010 00:07
Show Gist options
  • Select an option

  • Save matthuhiggins/717379 to your computer and use it in GitHub Desktop.

Select an option

Save matthuhiggins/717379 to your computer and use it in GitHub Desktop.
mysql_love_2
create_table :foo, :id => false do |t|
t.column :id, :manual_pk
t.column :bytes, :big_integer
end
module ActiveRecord
module ConnectionAdapters
class MysqlAdapter < AbstractAdapter
alias :original_native_database_types :native_database_types
def native_database_types
original_native_database_types.update(
:big_integer => { :name => "bigint", :limit => 21 },
:manual_pk => "int(11) NOT NULL PRIMARY KEY")
end
end
end
end
ActiveRecord::ConnectionAdapters::MysqlAdapter.register :big_integer, { :name => "bigint", :limit => 21 }
ActiveRecord::ConnectionAdapters::MysqlAdapter.register :manual_pk, "int(11) NOT NULL PRIMARY KEY"
create_table :foo, :id => false do |t|
t.manual_pk :id
t.big_integer :bytes
end
module ActiveRecord
module ConnectionAdapters
class TableDefinition
%w(big_integer manual_pk).each do |column_type|
class_eval <<-EOV
def #{column_type}(*args)
options = args.extract_options!
column_names = args
column_names.each { |name| column(name, '#{column_type}', options) }
end
EOV
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment