Table
in package
Class Table
Provides missing features for altering tables that are common in other supported databases, but are missing from SQLite. These are needed in order to support migrations during testing when another database is used as the primary engine, but SQLite in memory databases are used for faster test execution.
Table of Contents
- $db : Connection
- Database connection.
- $fields : array<string|int, mixed>
- All of the fields this table represents.
- $foreignKeys : array<string|int, mixed>
- All of the foreign keys in the table.
- $forge : Forge
- Handle to our forge.
- $keys : array<string|int, mixed>
- All of the unique/primary keys in the table.
- $prefixedTableName : string
- The name of the table, with database prefix
- $tableName : string
- The name of the table we're working with.
- __construct() : mixed
- Table constructor.
- dropColumn() : Table
- Drops columns from the table.
- dropForeignKey() : Table
- Drops a foreign key from this table so that it won't be recreated in the future.
- fromTable() : Table
- Reads an existing database table and collects all of the information needed to recreate this table.
- modifyColumn() : Table
- Modifies a field, including changing data type, renaming, etc.
- run() : bool
- Called after `fromTable` and any actions, like `dropColumn`, etc, to finalize the action. It creates a temp table, creates the new table with modifications, and copies the data over to the new table.
- copyData() : void
- Copies data from our old table to the new one, taking care map data correctly based on any columns that have been renamed.
- createTable() : mixed
- Creates the new table based on our current fields.
- dropIndexes() : null|void
- Attempts to drop all indexes and constraints from the database for this table.
- formatFields() : mixed
- Converts fields retrieved from the database to the format needed for creating fields with Forge.
- formatKeys() : mixed
- Converts keys retrieved from the database to the format needed to create later.
Properties
$db
Database connection.
protected
Connection
$db
$fields
All of the fields this table represents.
protected
array<string|int, mixed>
$fields
= []
$foreignKeys
All of the foreign keys in the table.
protected
array<string|int, mixed>
$foreignKeys
= []
$forge
Handle to our forge.
protected
Forge
$forge
$keys
All of the unique/primary keys in the table.
protected
array<string|int, mixed>
$keys
= []
$prefixedTableName
The name of the table, with database prefix
protected
string
$prefixedTableName
$tableName
The name of the table we're working with.
protected
string
$tableName
Methods
__construct()
Table constructor.
public
__construct(Connection $db, Forge $forge) : mixed
Parameters
- $db : Connection
- $forge : Forge
Return values
mixed —dropColumn()
Drops columns from the table.
public
dropColumn(string|array<string|int, mixed> $columns) : Table
Parameters
- $columns : string|array<string|int, mixed>
Return values
Table —dropForeignKey()
Drops a foreign key from this table so that it won't be recreated in the future.
public
dropForeignKey(string $column) : Table
Parameters
- $column : string
Return values
Table —fromTable()
Reads an existing database table and collects all of the information needed to recreate this table.
public
fromTable(string $table) : Table
Parameters
- $table : string
Return values
Table —modifyColumn()
Modifies a field, including changing data type, renaming, etc.
public
modifyColumn(array<string|int, mixed> $field) : Table
Parameters
- $field : array<string|int, mixed>
Return values
Table —run()
Called after `fromTable` and any actions, like `dropColumn`, etc, to finalize the action. It creates a temp table, creates the new table with modifications, and copies the data over to the new table.
public
run() : bool
Resets the connection dataCache to be sure changes are collected.
Return values
bool —copyData()
Copies data from our old table to the new one, taking care map data correctly based on any columns that have been renamed.
protected
copyData() : void
Return values
void —createTable()
Creates the new table based on our current fields.
protected
createTable() : mixed
Return values
mixed —dropIndexes()
Attempts to drop all indexes and constraints from the database for this table.
protected
dropIndexes() : null|void
Return values
null|void —formatFields()
Converts fields retrieved from the database to the format needed for creating fields with Forge.
protected
formatFields(array<string|int, mixed>|bool $fields) : mixed
Parameters
- $fields : array<string|int, mixed>|bool
Return values
mixed —formatKeys()
Converts keys retrieved from the database to the format needed to create later.
protected
formatKeys(mixed $keys) : mixed
Parameters
- $keys : mixed