Luminova Framework

PHP Luminova: Database Schema Operations

Last updated: 2026-11-28 20:57:12

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): bool

Parameters:

ParameterTypeDescription
$tableNamestringThe name of the table (non-empty string).
$onTableClosureThe callback function that defines the table structure.

Return:

bool - True if successful, otherwise false.

Throws:

The Closure table callback function must return an instance of Luminova\Database\Table.

The callback receives a Luminova\Database\Table instance.


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): bool

Parameters:

ParameterTypeDescription
$tableNamestringThe name of the table (non-empty string).
$onTableClosureThe callback function that defines the table structure.

Return:

bool - Returns true if the schema operation succeeds, or false otherwise.

Throws:

The Closure table callback function must return an instance of Luminova\Database\Table.

The callback receives a Luminova\Database\Table instance.


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'): bool

Parameters:

ParameterTypeDescription
$fromstringThe current name of the table.
$tostringThe new name of the table.
$databasestringThe 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:


dropIfExists

Drops a table if it exists.Call this from down() when reverting a migration.

public static function dropIfExists(string $tableName): bool

Parameters:

ParameterTypeDescription
$tableNamestringThe 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): bool

Parameters:

ParameterTypeDescription
$tableNamestringThe 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(): array

Return:

array<int,array<string,mixed>> - Returns schema operation reports. Each report contains the following keys.

KeyTypeDescription
messagestringOperation report message.
tablestring&#124;nullTable associated with the report.
passedboolWhether the operation passed.