Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Forge
/**
* List of unique keys.
*
* @var array
* @var list<int>
*/
protected $uniqueKeys = [];

Expand All @@ -64,7 +64,7 @@ class Forge
/**
* List of foreign keys.
*
* @var array
* @var list<array{field: list<string>, referenceTable: string, referenceField: list<string>, onDelete: string, onUpdate: string, fkName: string}>
*/
protected $foreignKeys = [];

Expand Down Expand Up @@ -146,7 +146,7 @@ class Forge
/**
* UNSIGNED support
*
* @var array|bool
* @var array<array-key, string>|bool
*/
protected $unsigned = true;

Expand Down Expand Up @@ -183,7 +183,7 @@ class Forge
/**
* Foreign Key Allowed Actions
*
* @var array
* @var list<string>
*/
protected $fkAllowActions = ['CASCADE', 'SET NULL', 'NO ACTION', 'RESTRICT', 'SET DEFAULT'];

Expand Down Expand Up @@ -324,7 +324,7 @@ public function dropDatabase(string $dbName): bool
/**
* Add Key
*
* @param array|string $key
* @param list<string>|string $key
*
* @return Forge
*/
Expand All @@ -346,7 +346,7 @@ public function addKey($key, bool $primary = false, bool $unique = false, string
/**
* Add Primary Key
*
* @param array|string $key
* @param list<string>|string $key
*
* @return Forge
*/
Expand All @@ -358,7 +358,7 @@ public function addPrimaryKey($key, string $keyName = '')
/**
* Add Unique Key
*
* @param array|string $key
* @param list<string>|string $key
*
* @return Forge
*/
Expand All @@ -370,7 +370,7 @@ public function addUniqueKey($key, string $keyName = '')
/**
* Add Field
*
* @param array<string, array|string>|string $fields Field array or Field string
* @param array<array-key, array<string, mixed>|string>|string $fields Field array or Field string
*
* @return Forge
*/
Expand Down Expand Up @@ -544,7 +544,7 @@ public function dropForeignKey(string $table, string $foreignName)
}

/**
* @param array $attributes Table attributes
* @param array<string, mixed> $attributes Table attributes
*
* @return bool
*
Expand Down Expand Up @@ -590,7 +590,7 @@ public function createTable(string $table, bool $ifNotExists = false, array $att
}

/**
* @param array $attributes Table attributes
* @param array<string, mixed> $attributes Table attributes
*
* @return string SQL string
*
Expand Down Expand Up @@ -626,6 +626,9 @@ protected function _createTable(string $table, bool $ifNotExists, array $attribu
);
}

/**
* @param array<string, mixed> $attributes
*/
protected function _createTableAttributes(array $attributes): string
{
$sql = '';
Expand Down Expand Up @@ -746,7 +749,7 @@ public function renameTable(string $tableName, string $newTableName)
}

/**
* @param array<string, array|string>|string $fields Field array or Field string
* @param array<array-key, array<string, mixed>|string>|string $fields Field array or Field string
*
* @throws DatabaseException
*/
Expand Down Expand Up @@ -804,7 +807,7 @@ public function dropColumn(string $table, $columnNames)
}

/**
* @param array<string, array|string>|string $fields Field array or Field string
* @param array<array-key, array<string, mixed>|string>|string $fields Field array or Field string
*
* @throws DatabaseException
*/
Expand Down Expand Up @@ -846,9 +849,9 @@ public function modifyColumn(string $table, $fields): bool
}

/**
* @param 'ADD'|'CHANGE'|'DROP' $alterType
* @param array|string $processedFields Processed column definitions
* or column names to DROP
* @param 'ADD'|'CHANGE'|'DROP' $alterType
* @param list<array<string, mixed>>|list<string>|string $processedFields Processed column definitions
* or column names to DROP
*
* @return ($alterType is 'DROP' ? string : false|list<string>|null)
*/
Expand Down Expand Up @@ -884,6 +887,8 @@ protected function _alterTable(string $alterType, string $table, $processedField

/**
* Returns $processedFields array from $this->fields data.
*
* @return list<array<string, mixed>>
*/
protected function _processFields(bool $createTable = false): array
{
Expand Down Expand Up @@ -973,6 +978,8 @@ protected function _processFields(bool $createTable = false): array

/**
* Converts $processedField array to field definition string.
*
* @param array<string, mixed> $processedField
*/
protected function _processColumn(array $processedField): string
{
Expand All @@ -988,6 +995,8 @@ protected function _processColumn(array $processedField): string
/**
* Performs a data type mapping between different databases.
*
* @param array<string, mixed> $attributes
*
* @return void
*/
protected function _attributeType(array &$attributes)
Expand All @@ -1005,6 +1014,9 @@ protected function _attributeType(array &$attributes)
* - array(TYPE => UTYPE) will change $field['type'],
* from TYPE to UTYPE in case of a match
*
* @param array<string, mixed> $attributes
* @param array<string, mixed> $field
*
* @return void
*/
protected function _attributeUnsigned(array &$attributes, array &$field)
Expand Down Expand Up @@ -1038,6 +1050,9 @@ protected function _attributeUnsigned(array &$attributes, array &$field)
}

/**
* @param array<string, mixed> $attributes
* @param array<string, mixed> $field
*
* @return void
*/
protected function _attributeDefault(array &$attributes, array &$field)
Expand All @@ -1062,6 +1077,9 @@ protected function _attributeDefault(array &$attributes, array &$field)
}

/**
* @param array<string, mixed> $attributes
* @param array<string, mixed> $field
*
* @return void
*/
protected function _attributeUnique(array &$attributes, array &$field)
Expand All @@ -1072,6 +1090,9 @@ protected function _attributeUnique(array &$attributes, array &$field)
}

/**
* @param array<string, mixed> $attributes
* @param array<string, mixed> $field
*
* @return void
*/
protected function _attributeAutoIncrement(array &$attributes, array &$field)
Expand Down Expand Up @@ -1164,6 +1185,8 @@ public function processIndexes(string $table): bool
* Generates SQL to add indexes
*
* @param bool $asQuery When true returns stand alone SQL, else partial SQL used with CREATE TABLE
*
* @return list<string>
*/
protected function _processIndexes(string $table, bool $asQuery = false): array
{
Expand Down Expand Up @@ -1210,6 +1233,8 @@ protected function _processIndexes(string $table, bool $asQuery = false): array
* Generates SQL to add foreign keys
*
* @param bool $asQuery When true returns stand alone SQL, else partial SQL used with CREATE TABLE
*
* @return list<string>
*/
protected function _processForeignKeys(string $table, bool $asQuery = false): array
{
Expand Down
25 changes: 3 additions & 22 deletions system/Database/MySQLi/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class Forge extends BaseForge
{
/**
* CREATE DATABASE statement
*
* @var string
*/
protected $createDatabaseStr = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';

Expand All @@ -38,8 +36,6 @@ class Forge extends BaseForge

/**
* DROP CONSTRAINT statement
*
* @var string
*/
protected $dropConstraintStr = 'ALTER TABLE %s DROP FOREIGN KEY %s';

Expand All @@ -56,7 +52,7 @@ class Forge extends BaseForge
/**
* UNSIGNED support
*
* @var array
* @var list<string>
*/
protected $_unsigned = [
'TINYINT',
Expand All @@ -76,7 +72,7 @@ class Forge extends BaseForge
/**
* Table Options list which required to be quoted
*
* @var array
* @var list<string>
*/
protected $_quoted_table_options = [
'COMMENT',
Expand All @@ -100,7 +96,7 @@ class Forge extends BaseForge
/**
* CREATE TABLE attributes
*
* @param array $attributes Associative array of table attributes
* @param array<string, mixed> $attributes Associative array of table attributes
*/
protected function _createTableAttributes(array $attributes): string
{
Expand Down Expand Up @@ -129,16 +125,6 @@ protected function _createTableAttributes(array $attributes): string
return $sql;
}

/**
* ALTER TABLE
*
* @param string $alterType ALTER type
* @param string $table Table name
* @param array|string $processedFields Processed column definitions
* or column names to DROP
*
* @return ($alterType is 'DROP' ? string : list<string>)
*/
protected function _alterTable(string $alterType, string $table, $processedFields)
{
if ($alterType === 'DROP') {
Expand Down Expand Up @@ -187,11 +173,6 @@ protected function _processColumn(array $processedField): string
. $extraClause;
}

/**
* Generates SQL to add indexes
*
* @param bool $asQuery When true returns stand alone SQL, else partial SQL used with CREATE TABLE
*/
protected function _processIndexes(string $table, bool $asQuery = false): array
{
$sqls = [''];
Expand Down
26 changes: 0 additions & 26 deletions system/Database/OCI8/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,28 @@ class Forge extends BaseForge

/**
* CREATE DATABASE statement
*
* @var false
*/
protected $createDatabaseStr = false;

/**
* CREATE TABLE IF statement
*
* @var false
*
* @deprecated This is no longer used.
*/
protected $createTableIfStr = false;

/**
* DROP TABLE IF EXISTS statement
*
* @var false
*/
protected $dropTableIfStr = false;

/**
* DROP DATABASE statement
*
* @var false
*/
protected $dropDatabaseStr = false;

/**
* UNSIGNED support
*
* @var array|bool
*/
protected $unsigned = false;

Expand All @@ -75,35 +65,19 @@ class Forge extends BaseForge

/**
* RENAME TABLE statement
*
* @var string
*/
protected $renameTableStr = 'ALTER TABLE %s RENAME TO %s';

/**
* DROP CONSTRAINT statement
*
* @var string
*/
protected $dropConstraintStr = 'ALTER TABLE %s DROP CONSTRAINT %s';

/**
* Foreign Key Allowed Actions
*
* @var array
*/
protected $fkAllowActions = ['CASCADE', 'SET NULL', 'NO ACTION'];

/**
* ALTER TABLE
*
* @param string $alterType ALTER type
* @param string $table Table name
* @param array|string $processedFields Processed column definitions
* or column names to DROP
*
* @return ($alterType is 'DROP' ? string : list<string>)
*/
protected function _alterTable(string $alterType, string $table, $processedFields)
{
$sql = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table);
Expand Down
Loading
Loading