Sha256: 42064d3d4c5de84e134a7cf001f60b8cfe04b0d1d2ca1e234f98219dc54a20ed

Contents?: true

Size: 1.55 KB

Versions: 6

Compression:

Stored size: 1.55 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    module Redshift
      if ActiveRecord.version < Gem::Version.new('5.1')
        # All this to add 'encoding' to Structure
        class ColumnDefinition < Struct.new(:name, :type, :limit, :precision, :scale, :default, :null, :first, :after, :auto_increment, :primary_key, :collation, :sql_type, :comment, :encoding)
          # From PostgreSQL to maintain compatability
          attr_accessor :array

          # From Abstract to maintain compatability
          def primary_key?
            primary_key || type.to_sym == :primary_key
          end
        end

        class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
          include ActiveRecord::ConnectionAdapters::PostgreSQL::ColumnMethods

          def new_column_definition(name, type, options) # :nodoc:
            super.tap do |column|
              column.encoding = options[:encoding]
            end
          end

          private

          def create_column_definition(name, type, options=nil)
            ColumnDefinition.new name, type, options
          end
        end
      else
        class TableDefinition < ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition
          def primary_key(name, type=:primary_key, **options)
            ints = %i(integer bigint)
            options[:auto_increment] ||= true if ints.include?(type) && !options.key?(:default)
            type = :primary_key if ints.include?(type) && options.delete(:auto_increment) == true
            super
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
postshift-0.3.0 lib/active_record/connection_adapters/redshift/schema_definitions.rb
postshift-0.2.1 lib/active_record/connection_adapters/redshift/schema_definitions.rb
postshift-0.2.0 lib/active_record/connection_adapters/redshift/schema_definitions.rb
postshift-0.1.2 lib/active_record/connection_adapters/redshift/schema_definitions.rb
postshift-0.1.1 lib/active_record/connection_adapters/redshift/schema_definitions.rb
postshift-0.1.0 lib/active_record/connection_adapters/redshift/schema_definitions.rb