Sha256: 8c479bf0aff9c24ccf6235a8d91f5272c08b58deb36872ae4f77607123eb2635

Contents?: true

Size: 1.6 KB

Versions: 11

Compression:

Stored size: 1.6 KB

Contents

module ArJdbc
  module PostgreSQL
    # @private copied (and adjusted) from native adapter 4.0/4.1/4.2
    class SchemaCreation < ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation

      private

      def visit_AddColumn(o)
        sql_type = type_to_sql(o.type.to_sym, o.limit, o.precision, o.scale)
        sql = "ADD COLUMN #{quote_column_name(o.name)} #{sql_type}"
        add_column_options!(sql, column_options(o))
      end unless AR42

      def visit_ColumnDefinition(o)
        sql = super
        if o.primary_key? && o.type == :uuid
          sql << " PRIMARY KEY "
          add_column_options!(sql, column_options(o))
        end
        sql
      end unless AR42

      def visit_ColumnDefinition(o)
        sql = super
        if o.primary_key? && o.type != :primary_key
          sql << " PRIMARY KEY "
          add_column_options!(sql, column_options(o))
        end
        sql
      end if AR42

      def add_column_options!(sql, options)
        if options[:array] || options[:column].try(:array)
          sql << '[]'
        end

        column = options.fetch(:column) { return super }
        if column.type == :uuid && options[:default] =~ /\(\)/
          sql << " DEFAULT #{options[:default]}"
        else
          super
        end
      end

      def type_for_column(column)
        if column.array
          @conn.lookup_cast_type("#{column.sql_type}[]")
        else
          super
        end
      end if AR42

    end

    def schema_creation
      SchemaCreation.new self
    end

  end
end if ::ActiveRecord::ConnectionAdapters::AbstractAdapter.const_defined? :SchemaCreation

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
activerecord-jdbc-adapter-1.3.25 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.24 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-ficoh-1.3.21-java lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.23 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.22 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-5.0.pre1 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.21 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.20 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.19 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.18 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.17 lib/arjdbc/postgresql/schema_creation.rb