PHP Class Migrations\CakeAdapter

Inheritance: implements Phinx\Db\Adapter\AdapterInterface
ファイルを表示 Open project: cakephp/migrations

Protected Properties

Property Type Description
$adapter Phinx\Db\Adapter\AdapterInterface Decorated adapter
$connection Cake\Database\Connection Database connection

Public Methods

Method Description
__construct ( Phinx\Db\Adapter\AdapterInterface $adapter, Connection $connection ) Constructor
addColumn ( Phinx\Db\Table $table, Phinx\Db\Table\Column $column ) : void Adds the specified column to a database table.
addForeignKey ( Phinx\Db\Table $table, Phinx\Db\Table\ForeignKey $foreignKey ) : void Adds the specified foreign key to a database table.
addIndex ( Phinx\Db\Table $table, Phinx\Db\Table\Index $index ) : void Adds the specified index to a database table.
beginTransaction ( ) : void Begin a transaction.
changeColumn ( string $tableName, string $columnName, Phinx\Db\Table\Column $newColumn ) : Phinx\Db\Table Change a table column type.
commitTransaction ( ) : void Commit a transaction.
connect ( ) : void Initializes the database connection.
createDatabase ( string $name, array $options = [] ) : void Creates a new database.
createSchemaTable ( ) : void Creates the schema table.
createTable ( Phinx\Db\Table $table ) : void Creates the specified database table.
disconnect ( ) : void Closes the database connection.
dropColumn ( string $tableName, string $columnName ) : void Drops the specified column.
dropDatabase ( string $name ) : void Drops the specified database.
dropForeignKey ( string $tableName, string[] $columns, string | null $constraint = null ) : void Drops the specified foreign key from a database table.
dropIndex ( string $tableName, mixed $columns ) : void Drops the specified index from a database table.
dropIndexByName ( string $tableName, string $indexName ) : void Drops the index specified by name from a database table.
dropTable ( string $tableName ) : void Drops the specified database table.
endCommandTimer ( ) : void Stop timing the current command and write the elapsed time to the output.
execute ( string $sql ) : integer Executes a SQL statement and returns the number of affected rows.
fetchAll ( string $sql ) : array Executes a query and returns an array of rows.
fetchRow ( string $sql ) : array Executes a query and returns only one row as an array.
getAdapterType ( ) : string Returns the adapter type.
getColumnTypes ( ) : array Returns an array of the supported Phinx column types.
getColumns ( string $tableName ) : Phinx\Db\Table\Column[] Returns table columns
getCommandStartTime ( ) : integer Gets the command start time
getConnection ( ) : PDO Gets the database connection
getOption ( string $name ) : mixed Get a single adapter option, or null if the option does not exist.
getOptions ( ) : array Get all adapter options.
getOutput ( ) : Symfony\Component\Console\Output\OutputInterface Gets the console output.
getSqlType ( string $type, integer | null $limit = null ) : string Converts the Phinx logical type to the adapter's SQL type.
getVersionLog ( ) : array Get all migration log entries, indexed by version number.
getVersions ( ) : array Get all migrated version numbers.
hasColumn ( string $tableName, string $columnName ) : boolean Checks to see if a column exists.
hasDatabase ( string $name ) : boolean Checks to see if a database exists.
hasForeignKey ( string $tableName, string[] $columns, string | null $constraint = null ) : boolean Checks to see if a foreign key exists.
hasIndex ( string $tableName, mixed $columns ) : boolean Checks to see if an index exists.
hasIndexByName ( string $tableName, string $indexName ) : boolean Checks to see if an index specified by name exists.
hasOption ( string $name ) : boolean Check if an option has been set.
hasSchemaTable ( ) : boolean Does the schema table exist?
hasTable ( string $tableName ) : boolean Checks to see if a table exists.
hasTransactions ( ) : boolean Does the adapter support transactions?
insert ( Phinx\Db\Table $table, array $row ) : void Inserts data into a table.
isValidColumnType ( Phinx\Db\Table\Column $column ) : boolean Checks that the given column is of a supported type.
migrated ( Phinx\Migration\MigrationInterface $migration, string $direction, integer $startTime, integer $endTime ) : Phinx\Db\Adapter\AdapterInterface Records a migration being run.
query ( string $sql ) : array Executes a SQL statement and returns the result as an array.
quoteColumnName ( string $columnName ) : string Quotes a column name for use in a query.
quoteTableName ( string $tableName ) : string Quotes a table name for use in a query.
renameColumn ( string $tableName, string $columnName, string $newColumnName ) : void Renames the specified column.
renameTable ( string $tableName, string $newName ) : void Renames the specified database table.
rollbackTransaction ( ) : void Rollback a transaction.
setCommandStartTime ( integer $time ) : Phinx\Db\Adapter\AdapterInterface Sets the command start time
setOptions ( array $options ) : Phinx\Db\Adapter\AdapterInterface Set adapter configuration options.
setOutput ( Symfony\Component\Console\Output\OutputInterface $output ) : Phinx\Db\Adapter\AdapterInterface Sets the console output.
startCommandTimer ( ) : void Start timing a command.
writeCommand ( string $command, array $args = [] ) : void Write a Phinx command to the output.

Method Details

__construct() public method

Constructor
public __construct ( Phinx\Db\Adapter\AdapterInterface $adapter, Connection $connection )
$adapter Phinx\Db\Adapter\AdapterInterface The original adapter to decorate.
$connection Cake\Database\Connection The connection to actually use.

addColumn() public method

Adds the specified column to a database table.
public addColumn ( Phinx\Db\Table $table, Phinx\Db\Table\Column $column ) : void
$table Phinx\Db\Table Table
$column Phinx\Db\Table\Column Column
return void

addForeignKey() public method

Adds the specified foreign key to a database table.
public addForeignKey ( Phinx\Db\Table $table, Phinx\Db\Table\ForeignKey $foreignKey ) : void
$table Phinx\Db\Table
$foreignKey Phinx\Db\Table\ForeignKey
return void

addIndex() public method

Adds the specified index to a database table.
public addIndex ( Phinx\Db\Table $table, Phinx\Db\Table\Index $index ) : void
$table Phinx\Db\Table Table
$index Phinx\Db\Table\Index Index
return void

beginTransaction() public method

Begin a transaction.
public beginTransaction ( ) : void
return void

changeColumn() public method

Change a table column type.
public changeColumn ( string $tableName, string $columnName, Phinx\Db\Table\Column $newColumn ) : Phinx\Db\Table
$tableName string Table Name
$columnName string Column Name
$newColumn Phinx\Db\Table\Column New Column
return Phinx\Db\Table

commitTransaction() public method

Commit a transaction.
public commitTransaction ( ) : void
return void

connect() public method

Initializes the database connection.
public connect ( ) : void
return void

createDatabase() public method

Creates a new database.
public createDatabase ( string $name, array $options = [] ) : void
$name string Database Name
$options array Options
return void

createSchemaTable() public method

Creates the schema table.
public createSchemaTable ( ) : void
return void

createTable() public method

Creates the specified database table.
public createTable ( Phinx\Db\Table $table ) : void
$table Phinx\Db\Table Table
return void

disconnect() public method

Closes the database connection.
public disconnect ( ) : void
return void

dropColumn() public method

Drops the specified column.
public dropColumn ( string $tableName, string $columnName ) : void
$tableName string Table Name
$columnName string Column Name
return void

dropDatabase() public method

Drops the specified database.
public dropDatabase ( string $name ) : void
$name string Database Name
return void

dropForeignKey() public method

If the adapter property is an instance of the \Phinx\Db\Adapter\SQLiteAdapter, a specific method will be called. The original one from Phinx contains a bug that can drop a table in certain conditions.
public dropForeignKey ( string $tableName, string[] $columns, string | null $constraint = null ) : void
$tableName string
$columns string[] Column(s)
$constraint string | null Constraint name
return void

dropIndex() public method

Drops the specified index from a database table.
public dropIndex ( string $tableName, mixed $columns ) : void
$tableName string
$columns mixed Column(s)
return void

dropIndexByName() public method

Drops the index specified by name from a database table.
public dropIndexByName ( string $tableName, string $indexName ) : void
$tableName string
$indexName string
return void

dropTable() public method

Drops the specified database table.
public dropTable ( string $tableName ) : void
$tableName string Table Name
return void

endCommandTimer() public method

Stop timing the current command and write the elapsed time to the output.
public endCommandTimer ( ) : void
return void

execute() public method

Executes a SQL statement and returns the number of affected rows.
public execute ( string $sql ) : integer
$sql string SQL
return integer

fetchAll() public method

Executes a query and returns an array of rows.
public fetchAll ( string $sql ) : array
$sql string SQL
return array

fetchRow() public method

Executes a query and returns only one row as an array.
public fetchRow ( string $sql ) : array
$sql string SQL
return array

getAdapterType() public method

Returns the adapter type.
public getAdapterType ( ) : string
return string

getColumnTypes() public method

Returns an array of the supported Phinx column types.
public getColumnTypes ( ) : array
return array

getColumns() public method

Returns table columns
public getColumns ( string $tableName ) : Phinx\Db\Table\Column[]
$tableName string Table Name
return Phinx\Db\Table\Column[]

getCommandStartTime() public method

Gets the command start time
public getCommandStartTime ( ) : integer
return integer

getConnection() public method

Gets the database connection
public getConnection ( ) : PDO
return PDO

getOption() public method

Get a single adapter option, or null if the option does not exist.
public getOption ( string $name ) : mixed
$name string
return mixed

getOptions() public method

Get all adapter options.
public getOptions ( ) : array
return array

getOutput() public method

Gets the console output.
public getOutput ( ) : Symfony\Component\Console\Output\OutputInterface
return Symfony\Component\Console\Output\OutputInterface

getSqlType() public method

Converts the Phinx logical type to the adapter's SQL type.
public getSqlType ( string $type, integer | null $limit = null ) : string
$type string
$limit integer | null
return string

getVersionLog() public method

Get all migration log entries, indexed by version number.
public getVersionLog ( ) : array
return array

getVersions() public method

Get all migrated version numbers.
public getVersions ( ) : array
return array

hasColumn() public method

Checks to see if a column exists.
public hasColumn ( string $tableName, string $columnName ) : boolean
$tableName string Table Name
$columnName string Column Name
return boolean

hasDatabase() public method

Checks to see if a database exists.
public hasDatabase ( string $name ) : boolean
$name string Database Name
return boolean

hasForeignKey() public method

Checks to see if a foreign key exists.
public hasForeignKey ( string $tableName, string[] $columns, string | null $constraint = null ) : boolean
$tableName string
$columns string[] Column(s)
$constraint string | null Constraint name
return boolean

hasIndex() public method

Checks to see if an index exists.
public hasIndex ( string $tableName, mixed $columns ) : boolean
$tableName string Table Name
$columns mixed Column(s)
return boolean

hasIndexByName() public method

Checks to see if an index specified by name exists.
public hasIndexByName ( string $tableName, string $indexName ) : boolean
$tableName string Table Name
$indexName string
return boolean

hasOption() public method

Check if an option has been set.
public hasOption ( string $name ) : boolean
$name string
return boolean

hasSchemaTable() public method

Does the schema table exist?
Deprecation: use hasTable instead.
public hasSchemaTable ( ) : boolean
return boolean

hasTable() public method

Checks to see if a table exists.
public hasTable ( string $tableName ) : boolean
$tableName string Table Name
return boolean

hasTransactions() public method

Does the adapter support transactions?
public hasTransactions ( ) : boolean
return boolean

insert() public method

Inserts data into a table.
public insert ( Phinx\Db\Table $table, array $row ) : void
$table Phinx\Db\Table where to insert data
$row array
return void

isValidColumnType() public method

Checks that the given column is of a supported type.
public isValidColumnType ( Phinx\Db\Table\Column $column ) : boolean
$column Phinx\Db\Table\Column
return boolean

migrated() public method

Records a migration being run.
public migrated ( Phinx\Migration\MigrationInterface $migration, string $direction, integer $startTime, integer $endTime ) : Phinx\Db\Adapter\AdapterInterface
$migration Phinx\Migration\MigrationInterface Migration
$direction string Direction
$startTime integer Start Time
$endTime integer End Time
return Phinx\Db\Adapter\AdapterInterface

query() public method

Executes a SQL statement and returns the result as an array.
public query ( string $sql ) : array
$sql string SQL
return array

quoteColumnName() public method

Quotes a column name for use in a query.
public quoteColumnName ( string $columnName ) : string
$columnName string Table Name
return string

quoteTableName() public method

Quotes a table name for use in a query.
public quoteTableName ( string $tableName ) : string
$tableName string Table Name
return string

renameColumn() public method

Renames the specified column.
public renameColumn ( string $tableName, string $columnName, string $newColumnName ) : void
$tableName string Table Name
$columnName string Column Name
$newColumnName string New Column Name
return void

renameTable() public method

Renames the specified database table.
public renameTable ( string $tableName, string $newName ) : void
$tableName string Table Name
$newName string New Name
return void

rollbackTransaction() public method

Rollback a transaction.
public rollbackTransaction ( ) : void
return void

setCommandStartTime() public method

Sets the command start time
public setCommandStartTime ( integer $time ) : Phinx\Db\Adapter\AdapterInterface
$time integer
return Phinx\Db\Adapter\AdapterInterface

setOptions() public method

Set adapter configuration options.
public setOptions ( array $options ) : Phinx\Db\Adapter\AdapterInterface
$options array
return Phinx\Db\Adapter\AdapterInterface

setOutput() public method

Sets the console output.
public setOutput ( Symfony\Component\Console\Output\OutputInterface $output ) : Phinx\Db\Adapter\AdapterInterface
$output Symfony\Component\Console\Output\OutputInterface Output
return Phinx\Db\Adapter\AdapterInterface

startCommandTimer() public method

Start timing a command.
public startCommandTimer ( ) : void
return void

writeCommand() public method

Write a Phinx command to the output.
public writeCommand ( string $command, array $args = [] ) : void
$command string Command Name
$args array Command Args
return void

Property Details

$adapter protected_oe property

Decorated adapter
protected AdapterInterface,Phinx\Db\Adapter $adapter
return Phinx\Db\Adapter\AdapterInterface

$connection protected_oe property

Database connection
protected Connection,Cake\Database $connection
return Cake\Database\Connection