Sha256: 5974d137d06ca17431795f7f0436203d18304c5446e19d229c245c4b511afc02

Contents?: true

Size: 1.15 KB

Versions: 16

Compression:

Stored size: 1.15 KB

Contents

module ArJdbc
  module PostgreSQL
    # @private copied from native adapter 4.0/4.1
    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

      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

      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
    end

    def schema_creation
      SchemaCreation.new self
    end

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
activerecord-jdbc-adapter-1.3.16 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.15 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.14 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.13 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.12 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.11 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.10 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.9 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.8 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.7 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.6 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.5 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.4 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.3 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.2 lib/arjdbc/postgresql/schema_creation.rb
activerecord-jdbc-adapter-1.3.1 lib/arjdbc/postgresql/schema_creation.rb