BigW Consortium Gitlab

postgresql_limit_fix.rb 856 Bytes
Newer Older
1 2
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
  class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
3 4 5 6 7 8 9 10 11 12 13 14 15 16
    module LimitFilter
      def add_column(table_name, column_name, type, options = {})
        options.delete(:limit) if type == :text
        super(table_name, column_name, type, options)
      end

      def change_column(table_name, column_name, type, options = {})
        options.delete(:limit) if type == :text
        super(table_name, column_name, type, options)
      end
    end

    prepend ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::LimitFilter

17 18 19 20 21 22 23 24 25 26 27
    class TableDefinition
      def text(*args)
        options = args.extract_options!
        options.delete(:limit)
        column_names = args
        type = :text
        column_names.each { |name| column(name, type, options) }
      end
    end
  end
end