class Table

A table is used to create a migration plan

Properties

protected string $name
protected array $columns
protected array $dependencies

Methods

__construct(string $model)

Create a new table (doesn't run CREATE TABLE)

string
name()

Get name

Column[]
columns()

Get columns

bool
dependent()

Returns true if depends on other tables

id(string $name = "id", int $size = 16)

Add an auto increment primary column

timestamps()

Adds created and modified timestamps

string(string $name, int $size = 255)

Add a string (varchar) column with an optional size

integer(string $name, int $size = 16)

Add an integer column with an optional size

int($name, $size = 16)

Alias for integer

uint(string $name, int $size = 16)

Add an unsigned int column with an optional size

bool(string $name)

Add a boolean column (using TINYINT(1))

timestamp(string $name)

Add a timestamp column

json(string $name)

Add a json column

add(string $name, string $type)

Add column to table

array
generateDependencies()

Compute dependencies

array
removeDependency(string $table)

Remove satisfied dependency and return new list

string
createQuery()

Get query string

bool
create(string $schema = "master")

Attemp to create a table with 'create table' instruction

bool
drop(string $schema = "master")

Drop the table

bool
migrate(Table $old = null, string $schema = "master")

Run migration for this table

Details

at line 32
__construct(string $model)

Create a new table (doesn't run CREATE TABLE)

Parameters

string $model class of the model or name of the table

at line 42
string name()

Get name

Return Value

string

at line 52
Column[] columns()

Get columns

Return Value

Column[]

at line 62
bool dependent()

Returns true if depends on other tables

Return Value

bool

at line 75
id(string $name = "id", int $size = 16)

Add an auto increment primary column

Parameters

string $name column name (default id)
int $size integer size (default 16)

at line 83
timestamps()

Adds created and modified timestamps

at line 97
Column string(string $name, int $size = 255)

Add a string (varchar) column with an optional size

Parameters

string $name column name
int $size optional size

Return Value

Column

at line 110
Column integer(string $name, int $size = 16)

Add an integer column with an optional size

Parameters

string $name column name
int $size optional size

Return Value

Column

at line 120
int($name, $size = 16)

Alias for integer

Parameters

$name
$size

See also

integer()

at line 133
Column uint(string $name, int $size = 16)

Add an unsigned int column with an optional size

Parameters

string $name column name
int $size optional size

Return Value

Column

at line 145
Column bool(string $name)

Add a boolean column (using TINYINT(1))

Parameters

string $name column name

Return Value

Column

at line 157
Column timestamp(string $name)

Add a timestamp column

Parameters

string $name column name

Return Value

Column

at line 169
Column json(string $name)

Add a json column

Parameters

string $name column name

Return Value

Column

at line 182
Column add(string $name, string $type)

Add column to table

Parameters

string $name column name
string $type column type

Return Value

Column added column

at line 199
array generateDependencies()

Compute dependencies

Compute dependencies based on column Used to build dependency treea and compute migration order

Return Value

array

at line 218
array removeDependency(string $table)

Remove satisfied dependency and return new list

Parameters

string $table dependency to remove

Return Value

array

at line 236
string createQuery()

Get query string

Return Value

string

at line 328
bool create(string $schema = "master")

Attemp to create a table with 'create table' instruction

Parameters

string $schema schema name

Return Value

bool false if fails

at line 340
bool drop(string $schema = "master")

Drop the table

Parameters

string $schema schema name

Return Value

bool false if fails

at line 353
bool migrate(Table $old = null, string $schema = "master")

Run migration for this table

Parameters

Table $old old table
string $schema schema name

Return Value

bool false if migration failed