Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Provide varbinary columns in a Migration.
- # Probably a better way to do this?
- #
- # Usage:
- # => t.varbinary :column, :limit => 20, ....[options]
- #
- ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
- def type_to_sql_with_varbinary(type, limit = nil, precision = nil, scale = nil)
- return type_to_sql_without_varbinary(type, limit, precision, scale) unless :varbinary == type.to_sym
- "varbinary(#{limit})"
- end
- alias_method_chain :type_to_sql, :varbinary
- end
- ActiveRecord::ConnectionAdapters::TableDefinition.class_eval do
- def varbinary(*args)
- options = args.extract_options!
- column_names = args
- type = :varbinary
- column_names.each { |name| column(name, type, options) }
- end
- end
- ActiveRecord::ConnectionAdapters::Table.class_eval do
- def varbinary(*args)
- options = args.extract_options!
- column_names = args
- type = :varbinary
- column_names.each do |name|
- column = ColumnDefinition.new(@base, name.to_s, type)
- if options[:limit]
- column.limit = options[:limit]
- elsif native[type].is_a?(Hash)
- column.limit = native[type][:limit]
- end
- column.precision = options[:precision]
- column.scale = options[:scale]
- column.default = options[:default]
- column.null = options[:null]
- @base.add_column(@table_name, name, column.sql_type, options)
- end
- end
- end
Add Comment
Please, Sign In to add comment