### Home Classes Methods

### In Files

- lib/sequel/database/schema_generator.rb
- lib/sequel/extensions/schema_dumper.rb

### Parent

Object

### Methods

- ::add_type_method
- ::new
- #check
- #column
- #composite_foreign_key
- #composite_primary_key
- #constraint
- #dump_columns
- #dump_constraints
- #dump_indexes
- #foreign_key
- #full_text_index
- #has_column?
- #index
- #method_missing
- #opts_inspect
- #primary_key
- #primary_key_name
- #spatial_index
- #unique

### Files

- CHANGELOG
- MIT-LICENSE
- README.rdoc
- active_record.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- cheat_sheet.rdoc
- dataset_basics.rdoc
- dataset_filtering.rdoc
- mass_assignment.rdoc
- migration.rdoc
- model_hooks.rdoc
- opening_databases.rdoc
- prepared_statements.rdoc
- querying.rdoc
- reflection.rdoc
- 1.0.txt
- 1.1.txt
- 1.3.txt
- 1.4.0.txt
- 1.5.0.txt
- 2.0.0.txt
- 2.1.0.txt
- 2.10.0.txt
- 2.11.0.txt
- 2.12.0.txt
- 2.2.0.txt
- 2.3.0.txt
- 2.4.0.txt
- 2.5.0.txt
- 2.6.0.txt
- 2.7.0.txt
- 2.8.0.txt
- 2.9.0.txt
- 3.0.0.txt
- 3.1.0.txt
- 3.10.0.txt
- 3.11.0.txt
- 3.12.0.txt
- 3.13.0.txt
- 3.14.0.txt
- 3.15.0.txt
- 3.16.0.txt
- 3.17.0.txt
- 3.18.0.txt
- 3.19.0.txt
- 3.2.0.txt
- 3.20.0.txt
- 3.21.0.txt
- 3.22.0.txt
- 3.23.0.txt
- 3.24.0.txt
- 3.25.0.txt
- 3.26.0.txt
- 3.27.0.txt
- 3.28.0.txt
- 3.29.0.txt
- 3.3.0.txt
- 3.30.0.txt
- 3.31.0.txt
- 3.32.0.txt
- 3.33.0.txt
- 3.4.0.txt
- 3.5.0.txt
- 3.6.0.txt
- 3.7.0.txt
- 3.8.0.txt
- 3.9.0.txt
- schema_modification.rdoc
- sharding.rdoc
- sql.rdoc
- testing.rdoc
- transactions.rdoc
- validations.rdoc
- virtual_rows.rdoc

### Class Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::ASTTransformer
- Sequel::Access
- Sequel::Access::DatabaseMethods
- Sequel::Access::DatasetMethods
- Sequel::Adapter
- Sequel::AdapterNotFound
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::ArbitraryServers
- Sequel::BasicObject
- Sequel::ColumnsIntrospection
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::DB2
- Sequel::DB2::DB2Error
- Sequel::DB2::Database
- Sequel::DB2::DatabaseMethods
- Sequel::DB2::Dataset
- Sequel::DB2::DatasetMethods
- Sequel::DBI
- Sequel::DBI::Database
- Sequel::DBI::Dataset
- Sequel::DataObjects
- Sequel::DataObjects::Database
- Sequel::DataObjects::Dataset
- Sequel::DataObjects::MySQL
- Sequel::DataObjects::MySQL::DatabaseMethods
- Sequel::DataObjects::MySQL::Dataset
- Sequel::DataObjects::Postgres
- Sequel::DataObjects::Postgres::AdapterMethods
- Sequel::DataObjects::Postgres::DatabaseMethods
- Sequel::DataObjects::Postgres::Dataset
- Sequel::DataObjects::SQLite
- Sequel::DataObjects::SQLite::DatabaseMethods
- Sequel::DataObjects::SQLite::Dataset
- Sequel::Database
- Sequel::DatabaseConnectionError
- Sequel::DatabaseDisconnectError
- Sequel::DatabaseError
- Sequel::Dataset
- Sequel::Dataset
- Sequel::Dataset::ArgumentMapper
- Sequel::Dataset::BindArgumentMethods
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::QueryBlockCopy
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::TYPE_TRANSLATOR
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::EmulateOffsetWithRowNumber
- Sequel::Error
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::DatabaseMethods
- Sequel::Firebird::Dataset
- Sequel::Firebird::DatasetMethods
- Sequel::HookFailed
- Sequel::HookFailed
- Sequel::IBMDB
- Sequel::IBMDB::Connection
- Sequel::IBMDB::Connection::Error
- Sequel::IBMDB::Database
- Sequel::IBMDB::Dataset
- Sequel::IBMDB::Dataset::CallableStatementMethods
- Sequel::IBMDB::Dataset::PreparedStatementMethods
- Sequel::IBMDB::Statement
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::DatabaseMethods
- Sequel::Informix::Dataset
- Sequel::Informix::DatasetMethods
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::DB2
- Sequel::JDBC::DB2::DatabaseMethods
- Sequel::JDBC::DB2::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Derby
- Sequel::JDBC::Derby::DatabaseMethods
- Sequel::JDBC::Derby::Dataset
- Sequel::JDBC::Firebird
- Sequel::JDBC::Firebird::DatabaseMethods
- Sequel::JDBC::Firebird::Dataset
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::HSQLDB
- Sequel::JDBC::HSQLDB::DatabaseMethods
- Sequel::JDBC::HSQLDB::Dataset
- Sequel::JDBC::Informix
- Sequel::JDBC::Informix::DatabaseMethods
- Sequel::JDBC::Informix::Dataset
- Sequel::JDBC::JTDS
- Sequel::JDBC::JTDS::DatabaseMethods
- Sequel::JDBC::JTDS::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MySQL
- Sequel::JDBC::MySQL::DatabaseMethods
- Sequel::JDBC::MySQL::Dataset
- Sequel::JDBC::Oracle
- Sequel::JDBC::Oracle::DatabaseMethods
- Sequel::JDBC::Oracle::Dataset
- Sequel::JDBC::Postgres
- Sequel::JDBC::Postgres::AdapterMethods
- Sequel::JDBC::Postgres::DatabaseMethods
- Sequel::JDBC::Postgres::Dataset
- Sequel::JDBC::SQLServer
- Sequel::JDBC::SQLServer::DatabaseMethods
- Sequel::JDBC::SQLServer::DatabaseMethods::MetadataDatasetMethods
- Sequel::JDBC::SQLServer::Dataset
- Sequel::JDBC::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::SQLite::Dataset
- Sequel::JDBC::Transactions
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationAlterTableReverser
- Sequel::MigrationDSL
- Sequel::MigrationReverser
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Mock
- Sequel::Mock::Connection
- Sequel::Mock::Database
- Sequel::Mock::Dataset
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- Sequel::Model::Associations::EagerGraphLoader
- Sequel::Model::Associations::InstanceMethods
- Sequel::Model::Associations::ManyToManyAssociationReflection
- Sequel::Model::Associations::ManyToOneAssociationReflection
- Sequel::Model::Associations::OneToManyAssociationReflection
- Sequel::Model::Associations::OneToOneAssociationReflection
- Sequel::Model::ClassMethods
- Sequel::Model::DatasetMethods
- Sequel::Model::Errors
- Sequel::Model::InstanceMethods
- Sequel::MySQL
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::DatasetMethods
- Sequel::MySQL::DatasetMethods::CallableStatementMethods
- Sequel::MySQL::DatasetMethods::PreparedStatementMethods
- Sequel::MySQL::DatasetMethods::StoredProcedureMethods
- Sequel::MySQL::PreparedStatements
- Sequel::MySQL::PreparedStatements::DatabaseMethods
- Sequel::Mysql2
- Sequel::Mysql2::Database
- Sequel::Mysql2::Dataset
- Sequel::NamedTimezones
- Sequel::NoExistingObject
- Sequel::NoExistingObject
- Sequel::NotImplemented
- Sequel::ODBC
- Sequel::ODBC::DB2
- Sequel::ODBC::DB2::DatabaseMethods
- Sequel::ODBC::DB2::Dataset
- Sequel::ODBC::Database
- Sequel::ODBC::Dataset
- Sequel::ODBC::MSSQL
- Sequel::ODBC::MSSQL::DatabaseMethods
- Sequel::ODBC::MSSQL::Dataset
- Sequel::OpenBase
- Sequel::OpenBase::Database
- Sequel::OpenBase::Dataset
- Sequel::Oracle
- Sequel::Oracle::Database
- Sequel::Oracle::DatabaseMethods
- Sequel::Oracle::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::ClassMethods
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AssociationAutoreloading
- Sequel::Plugins::AssociationAutoreloading::ClassMethods
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- Sequel::Plugins::AssociationPks::InstanceMethods
- Sequel::Plugins::AssociationProxies
- Sequel::Plugins::AssociationProxies::AssociationProxy
- Sequel::Plugins::AssociationProxies::ClassMethods
- Sequel::Plugins::BooleanReaders
- Sequel::Plugins::BooleanReaders::ClassMethods
- Sequel::Plugins::Caching
- Sequel::Plugins::Caching::ClassMethods
- Sequel::Plugins::Caching::InstanceMethods
- Sequel::Plugins::ClassTableInheritance
- Sequel::Plugins::ClassTableInheritance::ClassMethods
- Sequel::Plugins::ClassTableInheritance::InstanceMethods
- Sequel::Plugins::Composition
- Sequel::Plugins::Composition::ClassMethods
- Sequel::Plugins::Composition::InstanceMethods
- Sequel::Plugins::DatasetAssociations
- Sequel::Plugins::DatasetAssociations::ClassMethods
- Sequel::Plugins::DatasetAssociations::DatasetMethods
- Sequel::Plugins::DefaultsSetter
- Sequel::Plugins::DefaultsSetter::ClassMethods
- Sequel::Plugins::DefaultsSetter::InstanceMethods
- Sequel::Plugins::ForceEncoding
- Sequel::Plugins::ForceEncoding::ClassMethods
- Sequel::Plugins::ForceEncoding::InstanceMethods
- Sequel::Plugins::HookClassMethods
- Sequel::Plugins::HookClassMethods::ClassMethods
- Sequel::Plugins::HookClassMethods::InstanceMethods
- Sequel::Plugins::IdentityMap
- Sequel::Plugins::IdentityMap::ClassMethods
- Sequel::Plugins::IdentityMap::InstanceMethods
- Sequel::Plugins::InstanceFilters
- Sequel::Plugins::InstanceFilters::InstanceMethods
- Sequel::Plugins::InstanceHooks
- Sequel::Plugins::InstanceHooks::InstanceMethods
- Sequel::Plugins::JsonSerializer
- Sequel::Plugins::JsonSerializer::ClassMethods
- Sequel::Plugins::JsonSerializer::DatasetMethods
- Sequel::Plugins::JsonSerializer::InstanceMethods
- Sequel::Plugins::JsonSerializer::Literal
- Sequel::Plugins::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::List
- Sequel::Plugins::List::ClassMethods
- Sequel::Plugins::List::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- Sequel::Plugins::ManyThroughMany::DatasetMethods
- Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection
- Sequel::Plugins::NestedAttributes
- Sequel::Plugins::NestedAttributes::ClassMethods
- Sequel::Plugins::NestedAttributes::InstanceMethods
- Sequel::Plugins::OptimisticLocking
- Sequel::Plugins::OptimisticLocking::ClassMethods
- Sequel::Plugins::OptimisticLocking::InstanceMethods
- Sequel::Plugins::PreparedStatements
- Sequel::Plugins::PreparedStatements::ClassMethods
- Sequel::Plugins::PreparedStatements::InstanceMethods
- Sequel::Plugins::PreparedStatementsAssociations
- Sequel::Plugins::PreparedStatementsAssociations::ClassMethods
- Sequel::Plugins::PreparedStatementsAssociations::InstanceMethods
- Sequel::Plugins::PreparedStatementsSafe
- Sequel::Plugins::PreparedStatementsSafe::ClassMethods
- Sequel::Plugins::PreparedStatementsSafe::InstanceMethods
- Sequel::Plugins::PreparedStatementsWithPk
- Sequel::Plugins::PreparedStatementsWithPk::ClassMethods
- Sequel::Plugins::PreparedStatementsWithPk::DatasetMethods
- Sequel::Plugins::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::InstanceMethods
- Sequel::Plugins::SerializationModificationDetection
- Sequel::Plugins::SerializationModificationDetection::InstanceMethods
- Sequel::Plugins::Sharding
- Sequel::Plugins::Sharding::ClassMethods
- Sequel::Plugins::Sharding::DatasetMethods
- Sequel::Plugins::Sharding::InstanceMethods
- Sequel::Plugins::SingleTableInheritance
- Sequel::Plugins::SingleTableInheritance::ClassMethods
- Sequel::Plugins::SingleTableInheritance::InstanceMethods
- Sequel::Plugins::SkipCreateRefresh
- Sequel::Plugins::SkipCreateRefresh::InstanceMethods
- Sequel::Plugins::StringStripper
- Sequel::Plugins::StringStripper::InstanceMethods
- Sequel::Plugins::Subclasses
- Sequel::Plugins::Subclasses::ClassMethods
- Sequel::Plugins::TacticalEagerLoading
- Sequel::Plugins::TacticalEagerLoading::DatasetMethods
- Sequel::Plugins::TacticalEagerLoading::InstanceMethods
- Sequel::Plugins::Timestamps
- Sequel::Plugins::Timestamps::ClassMethods
- Sequel::Plugins::Timestamps::InstanceMethods
- Sequel::Plugins::Touch
- Sequel::Plugins::Touch::ClassMethods
- Sequel::Plugins::Touch::InstanceMethods
- Sequel::Plugins::Tree
- Sequel::Plugins::Tree::ClassMethods
- Sequel::Plugins::Tree::InstanceMethods
- Sequel::Plugins::Tree::SingleRoot
- Sequel::Plugins::Tree::SingleRoot::ClassMethods
- Sequel::Plugins::Tree::SingleRoot::InstanceMethods
- Sequel::Plugins::Tree::TreeMultipleRootError
- Sequel::Plugins::TypecastOnLoad
- Sequel::Plugins::TypecastOnLoad::ClassMethods
- Sequel::Plugins::TypecastOnLoad::InstanceMethods
- Sequel::Plugins::UpdatePrimaryKey
- Sequel::Plugins::UpdatePrimaryKey::ClassMethods
- Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
- Sequel::Plugins::ValidationClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods::Generator
- Sequel::Plugins::ValidationClassMethods::InstanceMethods
- Sequel::Plugins::ValidationHelpers
- Sequel::Plugins::ValidationHelpers::InstanceMethods
- Sequel::Plugins::XmlSerializer
- Sequel::Plugins::XmlSerializer::ClassMethods
- Sequel::Plugins::XmlSerializer::DatasetMethods
- Sequel::Plugins::XmlSerializer::InstanceMethods
- Sequel::PoolTimeout
- Sequel::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::AdapterMethods
- Sequel::Postgres::DatabaseMethods
- Sequel::Postgres::DatasetMethods
- Sequel::Postgres::DatasetMethods::PreparedStatementMethods
- Sequel::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- Sequel::Qualifier
- Sequel::Rollback
- Sequel::Rollback
- Sequel::SQL
- Sequel::SQL::AliasMethods
- Sequel::SQL::AliasedExpression
- Sequel::SQL::BitwiseMethods
- Sequel::SQL::Blob
- Sequel::SQL::BooleanConstant
- Sequel::SQL::BooleanExpression
- Sequel::SQL::BooleanMethods
- Sequel::SQL::CaseExpression
- Sequel::SQL::Cast
- Sequel::SQL::CastMethods
- Sequel::SQL::ColumnAll
- Sequel::SQL::ComplexExpression
- Sequel::SQL::ComplexExpressionMethods
- Sequel::SQL::Constant
- Sequel::SQL::Constants
- Sequel::SQL::Expression
- Sequel::SQL::Function
- Sequel::SQL::GenericComplexExpression
- Sequel::SQL::GenericExpression
- Sequel::SQL::Identifier
- Sequel::SQL::IdentifierMethods
- Sequel::SQL::InequalityMethods
- Sequel::SQL::JoinClause
- Sequel::SQL::JoinOnClause
- Sequel::SQL::JoinUsingClause
- Sequel::SQL::NegativeBooleanConstant
- Sequel::SQL::NoBooleanInputMethods
- Sequel::SQL::NumericExpression
- Sequel::SQL::NumericMethods
- Sequel::SQL::OrderMethods
- Sequel::SQL::OrderedExpression
- Sequel::SQL::PlaceholderLiteralString
- Sequel::SQL::QualifiedIdentifier
- Sequel::SQL::QualifyingMethods
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::ValueList
- Sequel::SQL::ValueList
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQLTime
- Sequel::SQLite
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::Generator
- Sequel::ServerBlock
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::Swift
- Sequel::Swift::Database
- Sequel::Swift::Dataset
- Sequel::Swift::MySQL
- Sequel::Swift::MySQL::DatabaseMethods
- Sequel::Swift::MySQL::Dataset
- Sequel::Swift::Postgres
- Sequel::Swift::Postgres::AdapterMethods
- Sequel::Swift::Postgres::DatabaseMethods
- Sequel::Swift::Postgres::Dataset
- Sequel::Swift::SQLite
- Sequel::Swift::SQLite::DatabaseMethods
- Sequel::Swift::SQLite::Dataset
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::ThreadedServerBlock
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::TinyTDS
- Sequel::TinyTDS::Database
- Sequel::TinyTDS::Dataset
- Sequel::TinyTDS::Dataset::ArgumentMapper
- Sequel::TinyTDS::Dataset::PreparedStatementMethods
- Sequel::ToDot
- Sequel::UnbindDuplicate
- Sequel::Unbinder
- Sequel::UndefinedAssociation
- Sequel::UnthreadedServerBlock
- Sequel::ValidationFailed
- Dataset
- Dataset::ArgumentMapper
- Dataset::BindArgumentMethods
- Dataset::PreparedStatementMethods
- String
- String::Inflections
- Array
- FalseClass
- Hash
- NilClass
- Numeric
- Object
- PGconn
- PGresult
- Proc
- Symbol
- TrueClass

No matching classes.

# Sequel::Schema::Generator

Schema::Generator is an internal class that the user is not expected to instantiate directly. Instances are created by Database#create_table. It is used to specify table creation parameters. It takes a Database object and a block of column/index/constraint specifications, and gives the Database a table description, which the database uses to create a table.

Schema::Generator has some methods but also includes method_missing, allowing users to specify column type as a method instead of using the column method, which makes for a nicer DSL.

For more information on Sequel’s support for schema modification, see the "Migrations and Schema Modification" guide.

### Constants

GENERIC_TYPES

  Classes specifying generic types that Sequel will convert to database-specific types.

### Attributes

columns[R]

Return the column hashes created by this generator

constraints[R]

Return the constraint hashes created by this generator

indexes[R]

Return the index hashes created by this generator

### Public Class Methods

add_type_method(*types) click to toggle source

Add a method for each of the given types that creates a column with that type as a constant. Types given should either already be constants/classes or a capitalized string/symbol with the same name as a constant/class.

        # File lib/sequel/database/schema_generator.rb, line 47
    47:       def self.add_type_method(*types)
    48:         types.each do |type|
    49:           class_eval("def #{type}(name, opts={}); column(name, #{type}, opts); end", __FILE__, __LINE__)
    50:         end
    51:       end

new(db, &block) click to toggle source

Set the database in which to create the table, and evaluate the block in the context of this object.

        # File lib/sequel/database/schema_generator.rb, line 33
    33:       def initialize(db, &block)
    34:         @db = db
    35:         @columns = []
    36:         @indexes = []
    37:         @constraints = []
    38:         @primary_key = nil
    39:         instance_eval(&block) if block
    40:         @columns.unshift(@primary_key) if @primary_key && !has_column?(primary_key_name)
    41:       end

### Public Instance Methods

check(*args, &block) click to toggle source

Add an unnamed constraint to the DDL, specified by the given block or args:

      check(:num=>1..5) # CHECK num >= 1 AND num <= 5
      check{num > 5} # CHECK num > 5

        # File lib/sequel/database/schema_generator.rb, line 58
    58:       def check(*args, &block)
    59:         constraint(nil, *args, &block)
    60:       end

column(name, type, opts = {}) click to toggle source

Add a column with the given name, type, and opts to the DDL.

      column :num, :integer
      # num INTEGER

      column :name, String, :null=>false, :default=>'a'
      # name varchar(255) NOT NULL DEFAULT 'a'

      inet :ip
      # ip inet

You can also create columns via method missing, so the following are equivalent:

      column :number, :integer
      integer :number

The following options are supported:

:default | The default value for the column.
:deferrable | This ensure Referential Integrity will work even if reference table will use for its foreign key a value that does not exists(yet) on referenced table. Basically it adds DEFERRABLE INITIALLY DEFERRED on key creation.
:index | Create an index on this column.
:key | For foreign key columns, the column in the associated table that this column references. Unnecessary if this column references the primary key of the associated table, except if you are using MySQL.
:null | Mark the column as allowing NULL values (if true), or not allowing NULL values (if false). If unspecified, will default to whatever the database default is.
:on_delete | Specify the behavior of this column when being deleted (:restrict, cascade, :set_null, :set_default, :no_action).
:on_update | Specify the behavior of this column when being updated (:restrict, cascade, :set_null, :set_default, :no_action).
:primary_key | Make the column as a single primary key column. This should only be used if you have a single, nonautoincrementing primary key column.
:size | The size of the column, generally used with string columns to specify the maximum number of characters the column will hold. An array of two integers can be provided to set the size and the precision, respectively, of decimal columns.
:unique | Mark the column as unique, generally has the same effect as creating a unique index on the column.
:unsigned | Make the column type unsigned, only useful for integer columns.

         # File lib/sequel/database/schema_generator.rb, line 108
    108:       def column(name, type, opts = {})
    109:         columns << {:name => name, :type => type}.merge(opts)
    110:         index(name) if opts[:index]
    111:       end

constraint(name, *args, &block) click to toggle source

Adds a named constraint (or unnamed if name is nil) to the DDL, with the given block or args.

      constraint(:blah, :num=>1..5) # CONSTRAINT blah CHECK num >= 1 AND num <= 5
      check(:foo){num > 5} # CONSTRAINT foo CHECK num > 5

         # File lib/sequel/database/schema_generator.rb, line 118
    118:       def constraint(name, *args, &block)
    119:         constraints << {:name => name, :type => :check, :check => block || args}
    120:       end

dump_columns() click to toggle source

Dump this generator’s columns to a string that could be evaled inside another instance to represent the same columns

         # File lib/sequel/extensions/schema_dumper.rb, line 190
    190:       def dump_columns
    191:         strings = []
    192:         cols = columns.dup
    193:         if pkn = primary_key_name
    194:           cols.delete_if{|x| x[:name] == pkn}
    195:           pk = @primary_key.dup
    196:           pkname = pk.delete(:name)
    197:           @db.serial_primary_key_options.each{|k,v| pk.delete(k) if v == pk[k]}
    198:           strings << "primary_key #{pkname.inspect}#{opts_inspect(pk)}"
    199:         end
    200:         cols.each do |c|
    201:           c = c.dup
    202:           name = c.delete(:name)
    203:           type = c.delete(:type)
    204:           opts = opts_inspect(c)
    205:           strings << if type.is_a?(Class)
    206:             "#{type.name} #{name.inspect}#{opts}"
    207:           else
    208:             "column #{name.inspect}, #{type.inspect}#{opts}"
    209:           end
    210:         end
    211:         strings.join("\n")
    212:       end

dump_constraints() click to toggle source

Dump this generator’s constraints to a string that could be evaled inside another instance to represent the same constraints

         # File lib/sequel/extensions/schema_dumper.rb, line 216
    216:       def dump_constraints
    217:         cs = constraints.map do |c|
    218:           c = c.dup
    219:           type = c.delete(:type)
    220:           case type
    221:           when :check
    222:             raise(Error, "can't dump check/constraint specified with Proc") if c[:check].is_a?(Proc)
    223:             name = c.delete(:name)
    224:             if !name and c[:check].length == 1 and c[:check].first.is_a?(Hash)
    225:               "check #{c[:check].first.inspect[1...-1]}"
    226:             else
    227:               "#{name ? "constraint #{name.inspect}," : 'check'} #{c[:check].map{|x| x.inspect}.join(', ')}"
    228:             end
    229:           else
    230:             cols = c.delete(:columns)
    231:             "#{type} #{cols.inspect}#{opts_inspect(c)}"
    232:           end
    233:         end
    234:         cs.join("\n")
    235:       end

dump_indexes(options={}) click to toggle source

Dump this generator’s indexes to a string that could be evaled inside another instance to represent the same indexes. Options:

- :add_index - Use add_index instead of index, so the methods can be called outside of a generator but inside a migration. The value of this option should be the table name to use.

- :drop_index - Same as add_index, but create drop_index statements.

- :ignore_errors - Add the ignore_errors option to the outputted indexes

         # File lib/sequel/extensions/schema_dumper.rb, line 244
    244:       def dump_indexes(options={})
    245:         is = indexes.map do |c|
    246:           c = c.dup
    247:           cols = c.delete(:columns)
    248:           if table = options[:add_index] || options[:drop_index]
    249:             "#{options[:drop_index] ? 'drop' : 'add'}_index #{table.inspect}, #{cols.inspect}#{', :ignore_errors=>true' if options[:ignore_errors]}#{opts_inspect(c)}"
    250:           else
    251:             "index #{cols.inspect}#{opts_inspect(c)}"
    252:           end
    253:         end
    254:         is.join("\n")
    255:       end

foreign_key(name, table=nil, opts = {}) click to toggle source

Add a foreign key in the table that references another table to the DDL. See column for available options.

      foreign_key(:artist_id) # artist_id INTEGER
      foreign_key(:artist_id, :artists) # artist_id INTEGER REFERENCES artists
      foreign_key(:artist_id, :artists, :key=>:id) # artist_id INTEGER REFERENCES artists(id)

If you want a foreign key constraint without adding a column (usually because it is a composite foreign key), you can provide an array of columns as the first argument, and you can provide the :name option to name the constraint:

      foreign_key([:artist_name, :artist_location], :artists, :name=>:artist_fk)
      # ADD CONSTRAINT artist_fk FOREIGN KEY (artist_name, artist_location) REFERENCES artists

         # File lib/sequel/database/schema_generator.rb, line 135
    135:       def foreign_key(name, table=nil, opts = {})
    136:         opts = case table
    137:         when Hash
    138:           table.merge(opts)
    139:         when Symbol
    140:           opts.merge(:table=>table)
    141:         when NilClass
    142:           opts
    143:         else
    144:           raise(Error, "The second argument to foreign_key should be a Hash, Symbol, or nil")
    145:         end
    146:         return composite_foreign_key(name, opts) if name.is_a?(Array)
    147:         column(name, Integer, opts)
    148:       end

full_text_index(columns, opts = {}) click to toggle source

Add a full text index on the given columns to the DDL.

         # File lib/sequel/database/schema_generator.rb, line 151
    151:       def full_text_index(columns, opts = {})
    152:         index(columns, opts.merge(:type => :full_text))
    153:       end

has_column?(name) click to toggle source

True if the DDL includes the creation of a column with the given name.

         # File lib/sequel/database/schema_generator.rb, line 156
    156:       def has_column?(name)
    157:         columns.any?{|c| c[:name] == name}
    158:       end

index(columns, opts = {}) click to toggle source

Add an index on the given column(s) with the given options to the DDL. The available options are:

:type | The type of index to use (only supported by some databases)
:unique | Make the index unique, so duplicate values are not allowed.
:where | Create a partial index (only supported by some databases)

      index :name
      # CREATE INDEX table_name_index ON table (name)

      index [:artist_id, :name]
      # CREATE INDEX table_artist_id_name_index ON table (artist_id, name)

         # File lib/sequel/database/schema_generator.rb, line 172
    172:       def index(columns, opts = {})
    173:         indexes << {:columns => Array(columns)}.merge(opts)
    174:       end

method_missing(type, name = nil, opts = {}) click to toggle source

Add a column with the given type, name, and opts to the DDL. See `column` for available options.

         # File lib/sequel/database/schema_generator.rb, line 178
    178:       def method_missing(type, name = nil, opts = {})
    179:         name ? column(name, type, opts) : super
    180:       end

primary_key(name, *args) click to toggle source

Adds an autoincrementing primary key column or a primary key constraint to the DDL. To create a constraint, the first argument should be an array of column symbols specifying the primary key columns. To create an autoincrementing primary key column, a single symbol can be used. In both cases, an options hash can be used as the second argument.

If you want to create a primary key column that is not autoincrementing, you should not use this method. Instead, you should use the regular `column` method with a `:primary_key=>true` option.

Examples:

      primary_key(:id)
      primary_key([:street_number, :house_number])

         # File lib/sequel/database/schema_generator.rb, line 195
    195:       def primary_key(name, *args)
    196:         return composite_primary_key(name, *args) if name.is_a?(Array)
    197:         @primary_key = @db.serial_primary_key_options.merge({:name => name})
    198:
    199:         if opts = args.pop
    200:           opts = {:type => opts} unless opts.is_a?(Hash)
    201:           if type = args.pop
    202:             opts.merge!(:type => type)
    203:           end
    204:           @primary_key.merge!(opts)
    205:         end
    206:         @primary_key
    207:       end

primary_key_name() click to toggle source

The name of the primary key for this generator, if it has a primary key.

         # File lib/sequel/database/schema_generator.rb, line 210
    210:       def primary_key_name
    211:         @primary_key[:name] if @primary_key
    212:       end

spatial_index(columns, opts = {}) click to toggle source

Add a spatial index on the given columns to the DDL.

         # File lib/sequel/database/schema_generator.rb, line 215
    215:       def spatial_index(columns, opts = {})
    216:         index(columns, opts.merge(:type => :spatial))
    217:       end

unique(columns, opts = {}) click to toggle source

Add a unique constraint on the given columns to the DDL.

      unique(:name) # UNIQUE (name)

         # File lib/sequel/database/schema_generator.rb, line 222
    222:       def unique(columns, opts = {})
    223:         constraints << {:type => :unique, :columns => Array(columns)}.merge(opts)
    224:       end

### Private Instance Methods

composite_foreign_key(columns, opts) click to toggle source

Add a composite foreign key constraint

         # File lib/sequel/database/schema_generator.rb, line 235
    235:       def composite_foreign_key(columns, opts)
    236:         constraints << {:type => :foreign_key, :columns => columns}.merge(opts)
    237:       end

composite_primary_key(columns, *args) click to toggle source

Add a composite primary key constraint

         # File lib/sequel/database/schema_generator.rb, line 229
    229:       def composite_primary_key(columns, *args)
    230:         opts = args.pop || {}
    231:         constraints << {:type => :primary_key, :columns => columns}.merge(opts)
    232:       end

opts_inspect(opts) click to toggle source

         # File lib/sequel/extensions/schema_dumper.rb, line 259
    259:       def opts_inspect(opts)
    260:         if opts[:default]
    261:           opts = opts.dup
    262:           de = case d = opts.delete(:default)
    263:           when BigDecimal, Sequel::SQL::Blob
    264:             "#{d.class.name}.new(#{d.to_s.inspect})"
    265:           when DateTime, Date
    266:             "#{d.class.name}.parse(#{d.to_s.inspect})"
    267:           when Time
    268:             "#{d.class.name}.parse(#{d.strftime('%H:%M:%S').inspect})"
    269:           else
    270:             d.inspect
    271:           end
    272:           ", :default=>#{de}#{", #{opts.inspect[1...-1]}" if opts.length > 0}"
    273:         else
    274:           ", #{opts.inspect[1...-1]}" if opts.length > 0
    275:         end
    276:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.