Doctrine 1.2.4
Doctrine_Migration_Base Class Reference

Public Member Functions

 addColumn ($tableName, $columnName, $type, $length=null, array $options=array())
 
 addIndex ($tableName, $indexName, array $definition)
 
 changeColumn ($tableName, $columnName, $type=null, $length=null, array $options=array())
 
 column ($upDown, $tableName, $columnName, $type=null, $length=null, array $options=array())
 
 constraint ($upDown, $tableName, $constraintName, array $definition)
 
 createConstraint ($tableName, $constraintName, array $definition)
 
 createForeignKey ($tableName, $name, array $definition)
 
 createPrimaryKey ($tableName, $columnNames)
 
 createTable ($tableName, array $fields=array(), array $options=array())
 
 dropConstraint ($tableName, $constraintName, $primary=false)
 
 dropForeignKey ($tableName, $name)
 
 dropPrimaryKey ($tableName, $columnNames)
 
 dropTable ($tableName)
 
 foreignKey ($upDown, $tableName, $name, array $definition=array())
 
 getChanges ()
 
 index ($upDown, $tableName, $indexName, array $definition=array())
 
 primaryKey ($direction, $tableName, $columnNames)
 
 removeColumn ($tableName, $columnName)
 
 removeIndex ($tableName, $indexName)
 
 renameColumn ($tableName, $oldColumnName, $newColumnName)
 
 renameTable ($oldTableName, $newTableName)
 
 table ($upDown, $tableName, array $fields=array(), array $options=array())
 

Static Public Member Functions

static getDefaultTableOptions ()
 
static setDefaultTableOptions (array $options)
 

Protected Member Functions

 _addChange ($type, array $change=array())
 

Detailed Description

Definition at line 33 of file Base.php.

Member Function Documentation

Doctrine_Migration_Base::_addChange (   $type,
array  $change = array() 
)
protected

Add a change to the stack of changes to execute

Parameters
string$typeThe type of change
array$changeThe array of information for the change
Returns
void

Definition at line 78 of file Base.php.

{
if (isset($change['upDown']) && $change['upDown'] !== null && isset(self::$_opposites[$type])) {
$upDown = $change['upDown'];
unset($change['upDown']);
if ($upDown == 'down') {
$opposite = self::$_opposites[$type];
return $this->_changes[] = array($opposite, $change);
}
}
return $this->_changes[] = array($type, $change);
}
Doctrine_Migration_Base::addColumn (   $tableName,
  $columnName,
  $type,
  $length = null,
array  $options = array() 
)

Add a add column change.

Parameters
string$tableNameName of the table
string$columnNameName of the column
string$typeType of the column
string$lengthLength of the column
array$optionsArray of options for the column
Returns
void

Definition at line 399 of file Base.php.

{
$this->column('up', $tableName, $columnName, $type, $length, $options);
}
Doctrine_Migration_Base::addIndex (   $tableName,
  $indexName,
array  $definition 
)

Add a add index change.

Parameters
string$tableNameName of the table
string$indexNameName of the index
array$definitionArray for the index definition
Returns
void

Definition at line 473 of file Base.php.

{
$this->index('up', $tableName, $indexName, $definition);
}
Doctrine_Migration_Base::changeColumn (   $tableName,
  $columnName,
  $type = null,
  $length = null,
array  $options = array() 
)

Add a change column change

Parameters
string$tableNameName of the table to change the column on
string$columnNameName of the column to change
string$typeNew type of column
string$lengthThe length of the column
array$optionsNew options for the column
Returns
void

Definition at line 441 of file Base.php.

{
$options = get_defined_vars();
$options['options']['length'] = $length;
$this->_addChange('changed_column', $options);
}
Doctrine_Migration_Base::column (   $upDown,
  $tableName,
  $columnName,
  $type = null,
  $length = null,
array  $options = array() 
)

Add a add or remove column change.

Parameters
string$upDownWhether to add the up(add) or down(remove) column change.
string$tableNameName of the table
string$columnNameName of the column
string$typeType of the column
string$lengthLength of the column
array$optionsArray of options for the column
Returns
void

Definition at line 377 of file Base.php.

{
$options = get_defined_vars();
if ( ! isset($options['options']['length'])) {
$options['options']['length'] = $length;
}
$options = array_merge($options, $options['options']);
unset($options['options']);
$this->_addChange('created_column', $options);
}
Doctrine_Migration_Base::constraint (   $upDown,
  $tableName,
  $constraintName,
array  $definition 
)

Add a create or drop constraint change.

Parameters
string$upDownWhether to add the up(create) or down(drop) create change.
string$tableNameName of the table.
string$constraintNameName of the constraint.
array$definitionArray for the constraint definition.
Returns
void

Definition at line 174 of file Base.php.

{
$options = get_defined_vars();
$this->_addChange('created_constraint', $options);
}
Doctrine_Migration_Base::createConstraint (   $tableName,
  $constraintName,
array  $definition 
)

Add a create constraint change.

Parameters
string$tableNameName of the table.
string$constraintnameName of the constraint.
array$definitionArray for the constraint definition.
Returns
void

Definition at line 189 of file Base.php.

{
$this->constraint('up', $tableName, $constraintName, $definition);
}
Doctrine_Migration_Base::createForeignKey (   $tableName,
  $name,
array  $definition 
)

Add a create foreign key change.

Parameters
string$tableNameName of the table.
string$nameName of the foreign key.
array$definitionArray for the foreign key definition
Returns
void

Definition at line 349 of file Base.php.

{
$this->foreignKey('up', $tableName, $name, $definition);
}
Doctrine_Migration_Base::createPrimaryKey (   $tableName,
  $columnNames 
)

Convenience method for creating primary keys

[php]
$columns = array(
    'id' => array(
        'type' => 'integer
        'autoincrement' => true
     )
);
$this->createPrimaryKey('my_table', $columns);

Equivalent to doing:

Parameters
string$tableNameName of the table
string$columnNamesArray of column names and column definitions
Returns
void

Definition at line 245 of file Base.php.

{
$autoincrement = false;
$fields = array();
// Add the columns
foreach ($columnNames as $columnName => $def) {
$type = $def['type'];
$length = isset($def['length']) ? $def['length'] : null;
$options = isset($def['options']) ? $def['options'] : array();
$this->addColumn($tableName, $columnName, $type, $length, $options);
$fields[$columnName] = array();
if (isset($def['autoincrement'])) {
$autoincrement = true;
$autoincrementColumn = $columnName;
$autoincrementType = $type;
$autoincrementLength = $length;
$autoincrementOptions = $options;
$autoincrementOptions['autoincrement'] = true;
}
}
// Create the primary constraint for the columns
$this->createConstraint($tableName, null, array(
'primary' => true,
'fields' => $fields
));
// If auto increment change the column to be so
if ($autoincrement) {
$this->changeColumn($tableName, $autoincrementColumn, $autoincrementType, $autoincrementLength, $autoincrementOptions);
}
}
Doctrine_Migration_Base::createTable (   $tableName,
array  $fields = array(),
array  $options = array() 
)

Add a create table change.

Parameters
string$tableNameName of the table
array$fieldsArray of fields for table
array$optionsArray of options for the table
Returns
void

Definition at line 135 of file Base.php.

{
$this->table('up', $tableName, $fields, array_merge(self::getDefaultTableOptions(), $options));
}
Doctrine_Migration_Base::dropConstraint (   $tableName,
  $constraintName,
  $primary = false 
)

Add a drop constraint change.

Parameters
string$tableNameName of the table.
string$constraintnameName of the constraint.
Returns
void

Definition at line 201 of file Base.php.

{
$this->constraint('down', $tableName, $constraintName, array('primary' => $primary));
}
Doctrine_Migration_Base::dropForeignKey (   $tableName,
  $name 
)

Add a drop foreign key change.

Parameters
string$tableNameName of the table.
string$nameName of the foreign key.
Returns
void

Definition at line 361 of file Base.php.

{
$this->foreignKey('down', $tableName, $name);
}
Doctrine_Migration_Base::dropPrimaryKey (   $tableName,
  $columnNames 
)

Convenience method for dropping primary keys.

[php]
$columns = array(
    'id' => array(
        'type' => 'integer
        'autoincrement' => true
     )
);
$this->dropPrimaryKey('my_table', $columns);

Equivalent to doing:

Parameters
string$tableNameName of the table
string$columnNamesArray of column names and column definitions
Returns
void

Definition at line 304 of file Base.php.

{
// un-autoincrement
foreach ((array) $columnNames as $columnName => $def) {
if (isset($def['autoincrement'])) {
$changeDef = $def;
unset($changeDef['autoincrement']);
$this->changeColumn($tableName, $columnName, $changeDef['type'], $changeDef['length'], $changeDef);
}
}
// Remove primary constraint
$this->dropConstraint($tableName, null, true);
// Remove columns
foreach (array_keys((array) $columnNames) as $columnName) {
$this->removeColumn($tableName, $columnName);
}
}
Doctrine_Migration_Base::dropTable (   $tableName)

Add a drop table change.

Parameters
string$tableNameName of the table
Returns
void

Definition at line 146 of file Base.php.

{
$this->table('down', $tableName);
}
Doctrine_Migration_Base::foreignKey (   $upDown,
  $tableName,
  $name,
array  $definition = array() 
)

Add a create or drop foreign key change.

Parameters
string$upDownWhether to add the up(create) or down(drop) foreign key change.
string$tableNameName of the table.
string$nameName of the foreign key.
array$definitionArray for the foreign key definition
Returns
void

Definition at line 333 of file Base.php.

{
$definition['name'] = $name;
$options = get_defined_vars();
$this->_addChange('created_foreign_key', $options);
}
Doctrine_Migration_Base::getChanges ( )

Get the changes that have been added on this migration class instance

Returns
array $changes

Definition at line 61 of file Base.php.

{
return $this->_changes;
}
static Doctrine_Migration_Base::getDefaultTableOptions ( )
static

Returns the default options for tables created using Doctrine_Migration_Base::createTable()

Returns
array

Definition at line 106 of file Base.php.

{
return self::$defaultTableOptions;
}
Doctrine_Migration_Base::index (   $upDown,
  $tableName,
  $indexName,
array  $definition = array() 
)

Add a add or remove index change.

Parameters
string$upDownWhether to add the up(add) or down(remove) index change.
string$tableNameName of the table
string$indexNameName of the index
array$definitionArray for the index definition
Returns
void

Definition at line 458 of file Base.php.

{
$options = get_defined_vars();
$this->_addChange('created_index', $options);
}
Doctrine_Migration_Base::primaryKey (   $direction,
  $tableName,
  $columnNames 
)

Convenience method for creating or dropping primary keys.

Parameters
string$direction
string$tableNameName of the table
string$columnNamesArray of column names and column definitions
Returns
void

Definition at line 214 of file Base.php.

{
if ($direction == 'up') {
$this->createPrimaryKey($tableName, $columnNames);
} else {
$this->dropPrimaryKey($tableName, $columnNames);
}
}
Doctrine_Migration_Base::removeColumn (   $tableName,
  $columnName 
)

Add a remove column change.

Parameters
string$tableNameName of the table
string$columnNameName of the column
Returns
void

Definition at line 411 of file Base.php.

{
$this->column('down', $tableName, $columnName);
}
Doctrine_Migration_Base::removeIndex (   $tableName,
  $indexName 
)

Add a remove index change.

Parameters
string$tableNameName of the table
string$indexNameName of the index
Returns
void

Definition at line 485 of file Base.php.

{
$this->index('down', $tableName, $indexName);
}
Doctrine_Migration_Base::renameColumn (   $tableName,
  $oldColumnName,
  $newColumnName 
)

Add a rename column change

Parameters
string$tableNameName of the table to rename the column on
string$oldColumnNameThe old column name
string$newColumnNameThe new column name
Returns
void

Definition at line 424 of file Base.php.

{
$options = get_defined_vars();
$this->_addChange('renamed_column', $options);
}
Doctrine_Migration_Base::renameTable (   $oldTableName,
  $newTableName 
)

Add a rename table change

Parameters
string$oldTableNameName of the table to change
string$newTableNameName to change the table to
Returns
void

Definition at line 158 of file Base.php.

{
$options = get_defined_vars();
$this->_addChange('renamed_table', $options);
}
static Doctrine_Migration_Base::setDefaultTableOptions ( array  $options)
static

Sets the default options for tables created using Doctrine_Migration_Base::createTable()

Parameters
array$options

Definition at line 96 of file Base.php.

{
self::$defaultTableOptions = $options;
}
Doctrine_Migration_Base::table (   $upDown,
  $tableName,
array  $fields = array(),
array  $options = array() 
)

Add a create or drop table change.

Parameters
string$upDownWhether to add the up(create) or down(drop) table change.
string$tableNameName of the table
array$fieldsArray of fields for table
array$optionsArray of options for the table
Returns
void

Definition at line 120 of file Base.php.

{
$options = get_defined_vars();
$this->_addChange('created_table', $options);
}

The documentation for this class was generated from the following file: