Class: SQL::Postgres::Table

### Home Classes Methods

### In Files

- lib/dm-migrations/sql/postgres.rb

### Parent

SQL::Table

### Methods

- ::new
- #query_column_constraints

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Adapters
- DataMapper::Migration
- DataMapper::MigrationRunner
- DataMapper::Migrations
- DataMapper::Migrations::DataObjectsAdapter
- DataMapper::Migrations::DataObjectsAdapter::ClassMethods
- DataMapper::Migrations::DuplicateMigration
- DataMapper::Migrations::Model
- DataMapper::Migrations::MysqlAdapter
- DataMapper::Migrations::MysqlAdapter::ClassMethods
- DataMapper::Migrations::OracleAdapter
- DataMapper::Migrations::OracleAdapter::ClassMethods
- DataMapper::Migrations::PostgresAdapter
- DataMapper::Migrations::PostgresAdapter::ClassMethods
- DataMapper::Migrations::Repository
- DataMapper::Migrations::SingletonMethods
- DataMapper::Migrations::SqliteAdapter
- DataMapper::Migrations::SqliteAdapter::ClassMethods
- DataMapper::Migrations::SqlserverAdapter
- DataMapper::Migrations::SqlserverAdapter::ClassMethods
- DataMapper::Migrations::YamlAdapter
- SQL
- SQL::Column
- SQL::Mysql
- SQL::Mysql::Column
- SQL::Mysql::Table
- SQL::Postgres
- SQL::Postgres::Column
- SQL::Postgres::Table
- SQL::Sqlite
- SQL::Sqlite::Column
- SQL::Sqlite::Table
- SQL::Table
- SQL::TableCreator
- SQL::TableCreator::Column
- SQL::TableCreator::SqlExpr
- SQL::TableModifier
- Spec
- Spec::Example
- Spec::Example::MigrationExampleGroup
- Spec::Matchers
- Spec::Matchers::Migration
- Spec::Matchers::Migration::HaveColumnMatcher
- Spec::Matchers::Migration::HaveTableMatcher
- Spec::Matchers::Migration::NullableColumnMatcher
- Spec::Matchers::Migration::PrimaryKeyMatcher
- Object

No matching classes.

# SQL::Postgres::Table

### Public Class Methods

new(adapter, table_name) click to toggle source

    # File lib/dm-migrations/sql/postgres.rb, line 44
    def initialize(adapter, table_name)
      @adapter, @name = adapter, table_name
      @columns = []
      adapter.query_table(table_name).each do |col_struct|
        @columns << SQL::Postgres::Column.new(col_struct)
      end

      query_column_constraints
    end

### Public Instance Methods

query_column_constraints() click to toggle source

    # File lib/dm-migrations/sql/postgres.rb, line 54
    def query_column_constraints
      @adapter.select(
        "SELECT * FROM information_schema.table_constraints WHERE table_name='#{@name}' AND table_schema=current_schema()"
      ).each do |table_constraint|
        @adapter.select(
          "SELECT * FROM information_schema.constraint_column_usage WHERE constraint_name='#{table_constraint.constraint_name}' AND table_schema=current_schema()"
        ).each do |constrained_column|
          @columns.each do |column|
            if column.name == constrained_column.column_name
              case table_constraint.constraint_type
              when "UNIQUE"       then column.unique = true
              when "PRIMARY KEY"  then column.primary_key = true
              end
            end
          end
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.