Skip to content

Commit

Permalink
Added SchemaInterface and implemented it in TableSchema class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Pustułka committed May 26, 2017
1 parent 8bd8b3b commit f211b70
Show file tree
Hide file tree
Showing 2 changed files with 427 additions and 114 deletions.
155 changes: 41 additions & 114 deletions src/Database/Schema/TableSchema.php
Expand Up @@ -17,6 +17,7 @@
use Cake\Database\Connection;
use Cake\Database\Exception;
use Cake\Database\Type;
use Cake\Datasource\SchemaInterface;

/**
* Represents a single table in a database schema.
Expand All @@ -29,7 +30,7 @@
* Schema\Collection objects. They can also be converted into SQL using the
* createSql(), dropSql() and truncateSql() methods.
*/
class TableSchema
class TableSchema implements SchemaInterface
{

/**
Expand Down Expand Up @@ -248,118 +249,6 @@ class TableSchema
*/
const INDEX_FULLTEXT = 'fulltext';

/**
* Binary column type
*
* @var string
*/
const TYPE_BINARY = 'binary';

/**
* Date column type
*
* @var string
*/
const TYPE_DATE = 'date';

/**
* Datetime column type
*
* @var string
*/
const TYPE_DATETIME = 'datetime';

/**
* Time column type
*
* @var string
*/
const TYPE_TIME = 'time';

/**
* Timestamp column type
*
* @var string
*/
const TYPE_TIMESTAMP = 'timestamp';

/**
* JSON column type
*
* @var string
*/
const TYPE_JSON = 'json';

/**
* String column type
*
* @var string
*/
const TYPE_STRING = 'string';

/**
* Text column type
*
* @var string
*/
const TYPE_TEXT = 'text';

/**
* Tiny Integer column type
*
* @var string
*/
const TYPE_TINYINTEGER = 'tinyinteger';

/**
* Small Integer column type
*
* @var string
*/
const TYPE_SMALLINTEGER = 'smallinteger';

/**
* Integer column type
*
* @var string
*/
const TYPE_INTEGER = 'integer';

/**
* Big Integer column type
*
* @var string
*/
const TYPE_BIGINTEGER = 'biginteger';

/**
* Float column type
*
* @var string
*/
const TYPE_FLOAT = 'float';

/**
* Decimal column type
*
* @var string
*/
const TYPE_DECIMAL = 'decimal';

/**
* Boolean column type
*
* @var string
*/
const TYPE_BOOLEAN = 'boolean';

/**
* UUID column type
*
* @var string
*/
const TYPE_UUID = 'uuid';

/**
* Foreign key cascade action
*
Expand Down Expand Up @@ -493,8 +382,20 @@ public function columns()
*
* @param string $name The column name.
* @return array|null Column data or null.
* @deprecated 3.5.0 Use getColumn() instead.
*/
public function column($name)
{
return $this->getColumn($name);
}

/**
* Get column data in the table.
*
* @param string $name The column name.
* @return array|null Column data or null.
*/
public function getColumn($name)
{
if (!isset($this->_columns[$name])) {
return null;
Expand Down Expand Up @@ -708,8 +609,20 @@ public function indexes()
*
* @param string $name The name of the index.
* @return array|null Array of index data, or null
* @deprecated 3.5.0 Use getIndex() instead.
*/
public function index($name)
{
return $this->getIndex($name);
}

/**
* Read information about an index based on name.
*
* @param string $name The name of the index.
* @return array|null Array of index data, or null
*/
public function getIndex($name)
{
if (!isset($this->_indexes[$name])) {
return null;
Expand Down Expand Up @@ -813,13 +726,15 @@ public function addConstraint($name, $attrs)
* Remove a constraint.
*
* @param string $name Name of the constraint to remove
* @return void
* @return $this
*/
public function dropConstraint($name)
{
if (isset($this->_constraints[$name])) {
unset($this->_constraints[$name]);
}

return $this;
}

/**
Expand Down Expand Up @@ -875,8 +790,20 @@ public function constraints()
*
* @param string $name The name of the constraint.
* @return array|null Array of constraint data, or null
* @deprecated 3.5.0 Use getConstraint() instead.
*/
public function constraint($name)
{
return $this->getConstraint($name);
}

/**
* Read information about a constraint based on name.
*
* @param string $name The name of the constraint.
* @return array|null Array of constraint data, or null
*/
public function getConstraint($name)
{
if (!isset($this->_constraints[$name])) {
return null;
Expand Down

0 comments on commit f211b70

Please sign in to comment.