CodeIgniter v4.5 API

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

Properties

$db  : Connection
Database connection.
$fields  : array<string, array<string, bool|int|string|null>>
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.

Methods

__construct()  : mixed
Table constructor.
addForeignKey()  : $this
Add a foreign key
addPrimaryKey()  : Table
Adds primary key
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.
dropPrimaryKey()  : Table
Drops the primary key
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()  : mixed
Copies data from our old table to the new one, taking care map data correctly based on any columns that have been renamed.
createTable()  : bool
Creates the new table based on our current fields.
dropIndexes()  : mixed
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()  : array<string, array{fields: string, type: string}>
Converts keys retrieved from the database to the format needed to create later.
isIntegerType()  : bool
Is INTEGER type?
isNumericType()  : bool
Is NUMERIC type?

Properties

$fields

All of the fields this table represents.

protected array<string, array<string, bool|int|string|null>> $fields = []

[name => attributes]

$foreignKeys

All of the foreign keys in the table.

protected array<string|int, mixed> $foreignKeys = []

$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

addForeignKey()

Add a foreign key

public addForeignKey(array<string|int, mixed> $foreignKeys) : $this
Parameters
$foreignKeys : array<string|int, mixed>
Return values
$this

addPrimaryKey()

Adds primary key

public addPrimaryKey(array<string|int, mixed> $fields) : Table
Parameters
$fields : array<string|int, mixed>
Return values
Table

dropColumn()

Drops columns from the table.

public dropColumn(array<int, string>|string $columns) : Table
Parameters
$columns : array<int, string>|string

Column names to drop.

Return values
Table

dropForeignKey()

Drops a foreign key from this table so that it won't be recreated in the future.

public dropForeignKey(string $foreignName) : Table
Parameters
$foreignName : string
Return values
Table

dropPrimaryKey()

Drops the primary key

public dropPrimaryKey() : Table
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<int, array<string, bool|int|string|null>> $fieldsToModify) : Table
Parameters
$fieldsToModify : array<int, array<string, bool|int|string|null>>
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() : mixed

createTable()

Creates the new table based on our current fields.

protected createTable() : bool
Return values
bool

dropIndexes()

Attempts to drop all indexes and constraints from the database for this table.

protected dropIndexes() : mixed

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
Tags
phpstan-return

($fields is array ? array : mixed)

formatKeys()

Converts keys retrieved from the database to the format needed to create later.

protected formatKeys(array<string, stdClass$keys) : array<string, array{fields: string, type: string}>
Parameters
$keys : array<string, stdClass>
Return values
array<string, array{fields: string, type: string}>

        
On this page

Search results