PHP Luminova: Database Schema Operations
Create, modify, rename, and drop database migration tables with the Schema class.
The Schema class applies database table changes. Use it from a migration’s up(), down(), or alter() hook and return the operation’s boolean result. The migration defines when a change runs. Schema executes the change. See the Migration Operations guide for hook examples and Novakit commands.
The callbacks passed to create() and modify() receive a Table instance. Use it to define columns, indexes, and other attributes, then return it. See Table Schema Definition for the available column types and modifiers.
Class Definition
- Class namespace:
Luminova\Database\Schema - This class is final.
Methods
create
Creates a new table using a callback function to build the table schema.
public static function create(string $tableName, Closure $onTable): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$tableName | string | The name of the table (non-empty string). |
$onTable | Closure | The callback function that defines the table structure. |
Return:
bool - True if successful, otherwise false.
Throws:
- Luminova\Exceptions\DatabaseException - If any error occurred.
The
Closuretable callback function must return an instance ofLuminova\Database\Table.The callback receives a
Luminova\Database\Tableinstance.
modify
Alters a table and its columns using a callback function to modify the table schema.Call this from alter() in your migration.
public static function modify(string $tableName, Closure $onTable): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$tableName | string | The name of the table (non-empty string). |
$onTable | Closure | The callback function that defines the table structure. |
Return:
bool - Returns true if the schema operation succeeds, or false otherwise.
Throws:
- Luminova\Exceptions\DatabaseException - If any error occurred.
The
Closuretable callback function must return an instance ofLuminova\Database\Table.The callback receives a
Luminova\Database\Tableinstance.
rename
Rename a table using the SQL dialect specified by $database.Call this from alter() in your migration.
public static function rename(string $from, string $to, string $database = 'mysql'): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$from | string | The current name of the table. |
$to | string | The new name of the table. |
$database | string | The type of database (e.g., 'sql-server', 'mysql', 'oracle', 'ms-access') (default: mysql). |
Return:
bool - Returns true if the schema operation succeeds, or false otherwise.
Throws:
- Luminova\Exceptions\DatabaseException - If any error occurred.
dropIfExists
Drops a table if it exists.Call this from down() when reverting a migration.
public static function dropIfExists(string $tableName): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$tableName | string | The name of the table (non-empty string). |
Return:
bool - Return true if table was dropped, otherwise false.
drop
Drops a table.Call this from down() when reverting a migration.
public static function drop(string $tableName): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$tableName | string | The name of the table (non-empty string). |
Return:
bool - Return true if table was dropped, otherwise false.
getReport
Get table execution reports.
public final function getReport(): arrayReturn:
array<int,array<string,mixed>> - Returns schema operation reports. Each report contains the following keys.
| Key | Type | Description |
|---|---|---|
message | string | Operation report message. |
table | string|null | Table associated with the report. |
passed | bool | Whether the operation passed. |