Skip to content

Commit

Permalink
Rename Schema/Table to Schema/TableSchema via class_alias()
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 2, 2016
1 parent 9e6a3c3 commit 703260a
Show file tree
Hide file tree
Showing 20 changed files with 280 additions and 278 deletions.
64 changes: 32 additions & 32 deletions src/Database/Schema/BaseSchema.php
Expand Up @@ -54,19 +54,19 @@ public function __construct(Driver $driver)
*/
protected function _foreignOnClause($on)
{
if ($on === Table::ACTION_SET_NULL) {
if ($on === TableSchema::ACTION_SET_NULL) {
return 'SET NULL';
}
if ($on === Table::ACTION_SET_DEFAULT) {
if ($on === TableSchema::ACTION_SET_DEFAULT) {
return 'SET DEFAULT';
}
if ($on === Table::ACTION_CASCADE) {
if ($on === TableSchema::ACTION_CASCADE) {
return 'CASCADE';
}
if ($on === Table::ACTION_RESTRICT) {
if ($on === TableSchema::ACTION_RESTRICT) {
return 'RESTRICT';
}
if ($on === Table::ACTION_NO_ACTION) {
if ($on === TableSchema::ACTION_NO_ACTION) {
return 'NO ACTION';
}
}
Expand All @@ -83,10 +83,10 @@ protected function _convertOnClause($clause)
return strtolower($clause);
}
if ($clause === 'NO ACTION') {
return Table::ACTION_NO_ACTION;
return TableSchema::ACTION_NO_ACTION;
}

return Table::ACTION_SET_NULL;
return TableSchema::ACTION_SET_NULL;
}

/**
Expand All @@ -111,14 +111,14 @@ protected function _convertConstraintColumns($references)
/**
* Generate the SQL to drop a table.
*
* @param \Cake\Database\Schema\Table $table Table instance
* @param \Cake\Database\Schema\TableSchema $schema Schema instance
* @return array SQL statements to drop a table.
*/
public function dropTableSql(Table $table)
public function dropTableSql(TableSchema $schema)
{
$sql = sprintf(
'DROP TABLE %s',
$this->_driver->quoteIdentifier($table->name())
$this->_driver->quoteIdentifier($schema->name())
);

return [$sql];
Expand Down Expand Up @@ -175,102 +175,102 @@ public function describeOptionsSql($tableName, $config)
/**
* Convert field description results into abstract schema fields.
*
* @param \Cake\Database\Schema\Table $table The table object to append fields to.
* @param \Cake\Database\Schema\TableSchema $schema The table object to append fields to.
* @param array $row The row data from `describeColumnSql`.
* @return void
*/
abstract public function convertColumnDescription(Table $table, $row);
abstract public function convertColumnDescription(TableSchema $schema, $row);

/**
* Convert an index description results into abstract schema indexes or constraints.
*
* @param \Cake\Database\Schema\Table $table The table object to append
* @param \Cake\Database\Schema\TableSchema $schema The table object to append
* an index or constraint to.
* @param array $row The row data from `describeIndexSql`.
* @return void
*/
abstract public function convertIndexDescription(Table $table, $row);
abstract public function convertIndexDescription(TableSchema $schema, $row);

/**
* Convert a foreign key description into constraints on the Table object.
*
* @param \Cake\Database\Schema\Table $table The table object to append
* @param \Cake\Database\Schema\TableSchema $schema The table object to append
* a constraint to.
* @param array $row The row data from `describeForeignKeySql`.
* @return void
*/
abstract public function convertForeignKeyDescription(Table $table, $row);
abstract public function convertForeignKeyDescription(TableSchema $schema, $row);

/**
* Convert options data into table options.
*
* @param \Cake\Database\Schema\Table $table Table instance.
* @param \Cake\Database\Schema\TableSchema $schema Table instance.
* @param array $row The row of data.
* @return void
*/
public function convertOptionsDescription(Table $table, $row)
public function convertOptionsDescription(TableSchema $schema, $row)
{
}

/**
* Generate the SQL to create a table.
*
* @param \Cake\Database\Schema\Table $table Table instance.
* @param \Cake\Database\Schema\TableSchema $schema Table instance.
* @param array $columns The columns to go inside the table.
* @param array $constraints The constraints for the table.
* @param array $indexes The indexes for the table.
* @return array SQL statements to create a table.
*/
abstract public function createTableSql(Table $table, $columns, $constraints, $indexes);
abstract public function createTableSql(TableSchema $schema, $columns, $constraints, $indexes);

/**
* Generate the SQL fragment for a single column in a table.
*
* @param \Cake\Database\Schema\Table $table The table instance the column is in.
* @param \Cake\Database\Schema\TableSchema $schema The table instance the column is in.
* @param string $name The name of the column.
* @return string SQL fragment.
*/
abstract public function columnSql(Table $table, $name);
abstract public function columnSql(TableSchema $schema, $name);

/**
* Generate the SQL queries needed to add foreign key constraints to the table
*
* @param \Cake\Database\Schema\Table $table The table instance the foreign key constraints are.
* @param \Cake\Database\Schema\TableSchema $schema The table instance the foreign key constraints are.
* @return array SQL fragment.
*/
abstract public function addConstraintSql(Table $table);
abstract public function addConstraintSql(TableSchema $schema);

/**
* Generate the SQL queries needed to drop foreign key constraints from the table
*
* @param \Cake\Database\Schema\Table $table The table instance the foreign key constraints are.
* @param \Cake\Database\Schema\TableSchema $schema The table instance the foreign key constraints are.
* @return array SQL fragment.
*/
abstract public function dropConstraintSql(Table $table);
abstract public function dropConstraintSql(TableSchema $schema);

/**
* Generate the SQL fragments for defining table constraints.
*
* @param \Cake\Database\Schema\Table $table The table instance the column is in.
* @param \Cake\Database\Schema\TableSchema $schema The table instance the column is in.
* @param string $name The name of the column.
* @return string SQL fragment.
*/
abstract public function constraintSql(Table $table, $name);
abstract public function constraintSql(TableSchema $schema, $name);

/**
* Generate the SQL fragment for a single index in a table.
*
* @param \Cake\Database\Schema\Table $table The table object the column is in.
* @param \Cake\Database\Schema\TableSchema $schema The table object the column is in.
* @param string $name The name of the column.
* @return string SQL fragment.
*/
abstract public function indexSql(Table $table, $name);
abstract public function indexSql(TableSchema $schema, $name);

/**
* Generate the SQL to truncate a table.
*
* @param \Cake\Database\Schema\Table $table Table instance.
* @param \Cake\Database\Schema\TableSchema $schema Table instance.
* @return array SQL statements to truncate a table.
*/
abstract public function truncateTableSql(Table $table);
abstract public function truncateTableSql(TableSchema $schema);
}
10 changes: 5 additions & 5 deletions src/Database/Schema/Collection.php
Expand Up @@ -83,7 +83,7 @@ public function listTables()
*
* @param string $name The name of the table to describe.
* @param array $options The options to use, see above.
* @return \Cake\Database\Schema\Table Object with column metadata.
* @return \Cake\Database\Schema\TableSchema Object with column metadata.
* @throws \Cake\Database\Exception when table cannot be described.
*/
public function describe($name, array $options = [])
Expand All @@ -92,7 +92,7 @@ public function describe($name, array $options = [])
if (strpos($name, '.')) {
list($config['schema'], $name) = explode('.', $name);
}
$table = new Table($name);
$table = new TableSchema($name);

$this->_reflect('Column', $name, $config, $table);
if (count($table->columns()) === 0) {
Expand All @@ -112,11 +112,11 @@ public function describe($name, array $options = [])
* @param string $stage The stage name.
* @param string $name The table name.
* @param array $config The config data.
* @param \Cake\Database\Schema\Table $table The table instance
* @param \Cake\Database\Schema\TableSchema $schema The table instance
* @return void
* @throws \Cake\Database\Exception on query failure.
*/
protected function _reflect($stage, $name, $config, $table)
protected function _reflect($stage, $name, $config, $schema)
{
$describeMethod = "describe{$stage}Sql";
$convertMethod = "convert{$stage}Description";
Expand All @@ -131,7 +131,7 @@ protected function _reflect($stage, $name, $config, $table)
throw new Exception($e->getMessage(), 500, $e);
}
foreach ($statement->fetchAll('assoc') as $row) {
$this->_dialect->{$convertMethod}($table, $row);
$this->_dialect->{$convertMethod}($schema, $row);
}
$statement->closeCursor();
}
Expand Down
30 changes: 15 additions & 15 deletions src/Database/Schema/MysqlSchema.php
Expand Up @@ -268,12 +268,12 @@ public function truncateTableSql(Table $table)
/**
* {@inheritDoc}
*/
public function createTableSql(Table $table, $columns, $constraints, $indexes)
public function createTableSql(Table $schema, $columns, $constraints, $indexes)
{
$content = implode(",\n", array_merge($columns, $constraints, $indexes));
$temporary = $table->temporary() ? ' TEMPORARY ' : ' ';
$content = sprintf("CREATE%sTABLE `%s` (\n%s\n)", $temporary, $table->name(), $content);
$options = $table->options();
$temporary = $schema->temporary() ? ' TEMPORARY ' : ' ';
$content = sprintf("CREATE%sTABLE `%s` (\n%s\n)", $temporary, $schema->name(), $content);
$options = $schema->options();
if (isset($options['engine'])) {
$content .= sprintf(' ENGINE=%s', $options['engine']);
}
Expand All @@ -290,9 +290,9 @@ public function createTableSql(Table $table, $columns, $constraints, $indexes)
/**
* {@inheritDoc}
*/
public function columnSql(Table $table, $name)
public function columnSql(Table $schema, $name)
{
$data = $table->column($name);
$data = $schema->column($name);
$out = $this->_driver->quoteIdentifier($name);
$nativeJson = $this->_driver->supportsNativeJson();

Expand Down Expand Up @@ -381,8 +381,8 @@ public function columnSql(Table $table, $name)
$out .= ' NOT NULL';
}
$addAutoIncrement = (
[$name] == (array)$table->primaryKey() &&
!$table->hasAutoIncrement()
[$name] == (array)$schema->primaryKey() &&
!$schema->hasAutoIncrement()
);
if (in_array($data['type'], ['integer', 'biginteger']) &&
($data['autoIncrement'] === true || $addAutoIncrement)
Expand Down Expand Up @@ -414,9 +414,9 @@ public function columnSql(Table $table, $name)
/**
* {@inheritDoc}
*/
public function constraintSql(Table $table, $name)
public function constraintSql(Table $schema, $name)
{
$data = $table->constraint($name);
$data = $schema->constraint($name);
if ($data['type'] === Table::CONSTRAINT_PRIMARY) {
$columns = array_map(
[$this->_driver, 'quoteIdentifier'],
Expand All @@ -441,16 +441,16 @@ public function constraintSql(Table $table, $name)
/**
* {@inheritDoc}
*/
public function addConstraintSql(Table $table)
public function addConstraintSql(Table $schema)
{
$sqlPattern = 'ALTER TABLE %s ADD %s;';
$sql = [];

foreach ($table->constraints() as $name) {
$constraint = $table->constraint($name);
foreach ($schema->constraints() as $name) {
$constraint = $schema->constraint($name);
if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) {
$tableName = $this->_driver->quoteIdentifier($table->name());
$sql[] = sprintf($sqlPattern, $tableName, $this->constraintSql($table, $name));
$tableName = $this->_driver->quoteIdentifier($schema->name());
$sql[] = sprintf($sqlPattern, $tableName, $this->constraintSql($schema, $name));
}
}

Expand Down

0 comments on commit 703260a

Please sign in to comment.