Sha256: 1c5fbc7011c72e937f988af3b10ee95f2cd5d9e7a8b265e4a145675960269f50

Contents?: true

Size: 1.59 KB

Versions: 27

Compression:

Stored size: 1.59 KB

Contents

module Torque
  module PostgreSQL
    module Adapter
      module SchemaCreation

        # Redefine original table creation command to ensure PostgreSQL standard
        def visit_TableDefinition(o)
          create_sql = "CREATE#{' TEMPORARY' if o.temporary}"
          create_sql << " TABLE #{quote_table_name(o.name)}"

          statements = o.columns.map{ |c| accept c }
          statements << accept(o.primary_keys) if o.primary_keys

          if supports_indexes_in_create?
            statements.concat(o.indexes.map do |column_name, options|
              index_in_create(o.name, column_name, options)
            end)
          end

          if supports_foreign_keys_in_create?
            statements.concat(o.foreign_keys.map do |to_table, options|
              foreign_key_in_create(o.name, to_table, options)
            end)
          end

          if o.as
            create_sql << " AS #{@conn.to_sql(o.as)}"
          else
            create_sql << " (#{statements.join(', ')})"
            add_table_options!(create_sql, table_options(o))

            if o.inherits.present?
              tables = o.inherits.map(&method(:quote_table_name))
              create_sql << " INHERITS ( #{tables.join(' , ')} )"
            end
          end

          create_sql
        end

        # Keep rails 5.0 and 5.1 compatibility
        def supports_foreign_keys_in_create?
          if defined?(super)
            super
          else
            supports_foreign_keys?
          end
        end

      end

      ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaCreation.prepend SchemaCreation
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
torque-postgresql-0.2.7 lib/torque/postgresql/adapter/schema_creation.rb
torque-postgresql-0.2.6 lib/torque/postgresql/adapter/schema_creation.rb
torque-postgresql-0.2.5 lib/torque/postgresql/adapter/schema_creation.rb
torque-postgresql-0.2.4 lib/torque/postgresql/adapter/schema_creation.rb
torque-postgresql-0.2.3 lib/torque/postgresql/adapter/schema_creation.rb
torque-postgresql-0.2.2 lib/torque/postgresql/adapter/schema_creation.rb
torque-postgresql-0.2.1 lib/torque/postgresql/adapter/schema_creation.rb