summaryrefslogtreecommitdiff
path: root/config/initializers/postgresql_limit_fix.rb
blob: 0cb3aaf4d24c9b674d23cfa352850c3f7ff0ee1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
  class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
    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

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

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

    alias_method_chain :add_column, :limit_filter
    alias_method_chain :change_column, :limit_filter
  end
end