Luminova Framework

PHP Luminova: Table Schema Definitions and Design Guidelines

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

Luminova’s schema builder for defining, creating, and modifying database tables.

The Luminova Database Table Schema allows developers to define database tables and their columns using an expressive, fluent syntax. It supports a wide range of data types and column modifiers, making it easy to create complex table structures.


Class Definition

  • Class namespace: Luminova\Database\Table

Constants

These constant variables allows you to easily use predefine values.

Constant NameDescriptionValue
DEFAULT_NONEDefault field value none.__NONE__
DEFAULT_TIMESTAMPDefault field value timestamp.CURRENT_TIMESTAMP
DEFAULT_NULLDefault field value null.NULL
INDEX_PRIMARY_KEYPrimary key.PRIMARY KEY
INDEX_FOREIGN_KEYForeign key.FOREIGN KEY
INDEX_UNIQUEUnique table index.UNIQUE
INDEX_DEFAULTIndexed table index.INDEX
INDEX_FULLTEXTFulltext table index.FULLTEXT
INDEX_SPATIALSpatial table index.SPATIAL
MYSQLGenerate schema for MySQL database.mysql
SQL_SERVERGenerate schema for SQL Server database.sql-server
MS_ACCESSGenerate schema for MS Access database.ms-access
SQLITEGenerate schema for SQLite.sqlite
ORACLEGenerate schema for Oracle database.oracle
COLUMN_NAMEReplaces format to column name.{__REPLACE_COLUMN_NAME__}

Properties

These properties can be use to specify database type, global, session, collection, comment or type of database table creation SQL schema to generate.

database

Specify the database type to generate schema for.

public string $database = 'mysql';

session

Initialize database sessions that will be created during migration.The array key as the session identifier/name while the value is the session value to apply.

/**
 * @var array<string, mixed>
 */
public array $session = [];

global

Initialize database globals that will be created during migration.The array key as the global identifier/name while the value is the global value to apply.

/**
 * @var array<string, mixed>
 */
public array $global = [];

Collation Property

Set the table collation type.

public ?string $collation = null;

Charset Property

Set the database default charset.

public ?string $charset = null;

Comment Property

Set the table command.

public ?string $comment = null;

ifNotExists

Specify weather to use create if not exists or just create table.

public bool $ifNotExists = false;

prettify

Specify if table query should be print in new line.

public bool $prettify = true;

engine

Set storage engines to handle SQL operations.

public ?string $engine = null;

Methods

These methods cover a wide range of database column types and useful column modifiers. To add a column, call the method corresponding to the desired data type, passing the column name as the first parameter followed by any additional required parameters (e.g., length or value) depending on the data type.

Examples

Add a column for NUMBER data type:

$table->number('product_id', 10);

Add a column for GEOMETRYCOLLECTION data type:

$table->geometryCollection('geometry');

constructor

Constructor to initialize the table with a name.

public function __construct(
    string $tableName,
    string $database = self::MYSQL,
    bool $ifNotExists = false,
    ?string $collation = null,
    ?string $comment = null
)

Parameters:

ParameterTypeDescription
$tableNamestringThe name of the table.
$databasestringThe database type (default: MYSQL).
$ifNotExistsboolWhether to add if not exists (default: false).
$collation?stringOptional table collation type (default: null).
$comment?stringOptional table comment (default: null).

Throws:


string

Create a new column to store string values.

string(string $name, string $type = 'VARCHAR', int|null $length = 255): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$typestringThe column data type (default VARCHAR).
$lengthint|null(Optional) The length or size of the column (default: 255).

Return:

self - Return table class instance.


integer

Alias for int method, to creates an INT column with optional length.

integer(string $name, ?int $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


number

Creates an NUMBER column with optional length.

number(string $name, ?int $precision = null, ?int $scale = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$precisionint|nullThe optional precision length of the column (default: NULL).
$scaleint|nullThe optional scale length of the column (default: NULL).

Return:

self - Return table class instance.


decimal

Creates a DECIMAL column with precision and scale length.

decimal(string $name, int $precision = 10, int $scale = 0): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$precisionintThe precision of the decimal (default: 10).
$scaleintThe scale of the decimal (default: 0).

Return:

self - Return table class instance.


float

Creates a FLOAT column with precision and scale length.

float(string $name, int $precision = 10, int $scale = 2): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$precisionintThe precision of the float (default: 10).
$scaleintThe scale of the float (default: 2).

Return:

self - Return table class instance.


double

Creates a DOUBLE column with precision and scale length.

double(string $name, int $precision = 10, int $scale = 2): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


text

Creates a TEXT column with optional length.

text(string $name, int|null $length = 255): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column (default: 255).

Return:

self - Return table class instance.


date

Creates a DATE column with optional length.

date(string $name, int|null $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


enum

Creates an ENUM column with default values.

public function enum(string $name, array $values): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$valuesarray<array-key, mixed>The values for the ENUM column.

Return:

self - Return table class instance.


set

Creates a SET column with default values.

public function set(string $name, array $values): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$valuesarray<array-key, mixed>The values for the SET column.

Return:

self - Return table class instance.


id

An alias for bigInt method, to creates a primary key column id set to auto increment, BIGINT and UNSIGNED attribute.

public function id(string $name = 'id'): self

Parameters:

ParameterTypeDescription
$namestringOptional column name for id (default: id).

Return:

self - Return table class instance.


ulid

Creates a new column for ULID using CHAR(25).This method defines a column for storing ULIDs (Universally Unique Lexicographically Sortable Identifiers).

public function ulid(string $name = 'ulid'): self

Parameters:

ParameterTypeDescription
$namestringThe name of the ulid column (default: ulid).

Return:

self - Return table class instance.


uuid

Creates a new column for UUID using CHAR(36).This method defines a column for storing UUIDs (Universally Unique Identifiers).

public function uuid(string $name = 'uuid'): self

Parameters:

ParameterTypeDescription
$namestringThe name of the UUID column (default: uuid).

Return:

self - Return table class instance.


timestamps

Creates columns for timestamps with the names created_on and updated_on.Both columns are set to be NULLABLE with a default value of NULL.

public function timestamps(?int $precision = null): self

Parameters:

ParameterTypeDescription
$precision?intOptional precision for the timestamp columns (default: NULL).

Return:

self - Return table class instance.

Note: Trying to add other attributes to this column will not take any effect on created_on, as it will only add to updated_on


datetime

Creates a DATETIME column with optional precision length.

datetime(string $name, int|null $precision = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$precisionint|nullThe optional precision length of the column.

Return:

self - Return table class instance.


timestamp

Creates a TIMESTAMP column with optional precision length.

timestamp(string $name, int|null $precision = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$precisionint|nullThe optional precision length of the column.

Return:

self - Return table class instance.


time

Creates a TIME column with optional precision length.

time(string $name, int|null $precision = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$precisionint|nullThe optional precision length of the column.

Return:

self - Return table class instance.


year

Creates a YEAR column with optional precision length.

year(string $name, int|null $precision = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$precisionint|nullThe optional precision length of the column.

Return:

self - Return table class instance.


json

Creates a JSON column.

json(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


Column Modifiers

In addition to column types, you can also apply modifiers to columns to define constraints and default values. Here are the predefined modifiers.

type

Updates the column data type.Use this method to modify or specify the data type of the column if necessary.

public function type(string $type): self

Parameters:

ParameterTypeDescription
$typestringThe new data type for the column.

Return:

self - Return table class instance.


attribute

Adds additional attributes to the current column.This method allows for specifying additional column attributes such as UNSIGNED, AUTO_INCREMENT, etc.

public function attribute(string $attribute): self

Parameters:

ParameterTypeDescription
$attributestringThe attribute to add to the column definition.

Return:

self - Return table class instance.

Multiple attributes can be chained together for the same column.

Example Usage

Adds the UNSIGNED and AUTO_INCREMENT attribute to the column.

$table->attribute('UNSIGNED')->attribute('AUTO_INCREMENT');

entry

Define additional column entry that will be added to the table definition.

public function entry(string $query): self

Parameters:

ParameterTypeDescription
$querystringThe entry query string to add.

Return:

self - Returns the table class instance.

Example Usage

This method allows adding custom column entries that will appear in the CREATE TABLE statement.

$table->entry("CONSTRAINT fk_foo_bar FOREIGN KEY (foo_id) REFERENCES bar(bar_id)");

Passing fields string into the table definitions with.

$table->entry("name varchar(50) NOT NULL DEFAULT 'default value'");

exec

Define additional execution constraint to execute after table creation.

public function exec(string $query): self

Parameters:

ParameterTypeDescription
$querystringThe execution query string to add.

Return:

self - Returns the table class instance.

Example Usage

This method adds execution queries that will be executed after the table is created.

$table->exec("ALTER TABLE foo ADD CONSTRAINT ...");

Alter column after table creation definition.

$table->exec("ALTER TABLE users MODIFY COLUMN column_name INT VISIBLE");

check

Define a CHECK constraint for a column.

public function check(string $column, string $operator, string|float|int|null $value): self

Parameters:

ParameterTypeDescription
$columnstringThe name of the column to apply the CHECK constraint on.
$operatorstringThe comparison operator for the CHECK constraint (e.g., '=', '>', '<=').
$valuestring&#124;float&#124;int&#124;nullThe value to compare against in the CHECK constraint.

Return:

self - Returns the table class instance.

Example Usage

This method adds a CHECK constraint for the specified column, with an operator and value.

$table->check("column_name", ">=", 100);

autoIncrement

Sets the column to auto increment.This method adds the AUTO INCREMENT attribute to an integer column,suitable for primary key columns to automatically generate unique values.

public function autoIncrement(int $start = 1, int $increment = 1): self

Parameters:

ParameterTypeDescription
$startintThe starting value for the auto increment (default 1).
$incrementintThe increment value for each auto increment step.

Return:

self - Return table class instance.


nullable

Sets the column to nullable.This method sets the column to allow NULL values in the database.

public function nullable(bool $nullable = true): self

Parameters:

ParameterTypeDescription
$nullableboolOptional pass false for not nullable (default: true).

Return:

self - Return table class instance.


invisible

Sets the column to invisible in MYSQL.Invisible columns are not shown in SELECT * queries but can still be accessed when explicitly specified in the query.

public function invisible(): self

Return:

self - Return table class instance.

The INVISIBLE attribute can only be used in MySQL 8.0.23 and later.


visible

Sets the column to visible in MYSQL.This is useful for alter when column was previously set to INVISIBLE.

public function visible(): self

Return:

self - Return table class instance.

The VISIBLE attribute can only be used in MySQL 8.0.23 and later.


default

Sets the default value for the column, optionally you can use predefine defaults Table::DEFAULT_*.This method assigns a default value to the column, which can be a string, integer, float, boolean, array, json object or null.It is often used to provide a fallback value when no explicit value is provided during record insertion.

public function default(mixed $value = null): self

Parameters:

ParameterTypeDescription
$valuemixedThe default value for the column (default: NULL).

Return:

self - Return table class instance.


length

Sets the precision and optional scale length for a column.

public function length(int $precision, ?int $scale = null): self

Parameters:

ParameterTypeDescription
$precisionintThe precision length of the column.
$scale?intOptional scale length of decimal, float, or double column types (default: NULL).

Return:

self - Return table class instance.


collation

Sets the collation for column.

public function collation(string $collate): self

Parameters:

ParameterTypeDescription
$collatestringThe column collation to use (e.g. utf8_unicode_ci).

Return:

self - Return table class instance.


charset

Sets the charset for column.

public function charset(string $charset): self

Parameters:

ParameterTypeDescription
$charsetstringThe column charset to use (e.g. utf8).

Return:

self - Return table class instance.


index

Define an index constraint on a column.This method allows you to specify various types of index constraints on a table column,such as default, unique, fulltext, spatial, or primary key.

public function index(string $index = self::INDEX_DEFAULT): self

Parameters:

ParameterTypeDescription
$indexstringThe type of index constraint to apply (default: INDEX).

Return:

self - Return table class instance.

Throws:

Constants Index Types:

  • Table::INDEX_DEFAULT: Creates a standard index on the column.
  • Table::INDEX_UNIQUE: Creates a unique index on the column.
  • Table::INDEX_FULLTEXT: Creates a fulltext index on the column (MySQL specific).
  • Table::INDEX_SPATIAL: Creates a spatial index on the column (MySQL specific).
  • Table::INDEX_PRIMARY_KEY: Sets the column as a primary key.

defaultIndex

Sets a column index as INDEX (e.g., column_name INDEX).This method adds a regular index to the column, optimizing data retrieval and query performance.

public function defaultIndex(?string $columns = null): self

Parameters:

ParameterTypeDescription
$columns?stringThe column names to apply the index on, separated by commas (e.g., column1,column2) (optional).

Return:

self - Returns the table class instance.


fullText

Sets a column index as FULLTEXT (e.g., column_name FULLTEXT INDEX).This method specifies that the column is optimized for full-text searches, allowing efficient keyword-based searching of text within the column.

public function fullText(?string $columns = null): self

Parameters:

ParameterTypeDescription
$columns?stringThe column names to apply the index on, separated by commas (e.g., column1,column2) (optional).

Return:

self - Return table class instance.


spatial

Sets a column index as SPATIAL (e.g., column_name SPATIAL INDEX).This method specifies that the column is used for spatial data types, enabling efficient querying of spatial data like points, lines, and polygons.

public function spatial(?string $columns = null): self

Parameters:

ParameterTypeDescription
$columns?stringThe column names to apply the index on, separated by commas (e.g., column1,column2) (optional).

Return:

self - Return table class instance.


unique

Sets a column as a UNIQUE key inline with the column definition (e.g., column_name UNIQUE INDEX).This method specifies that the column must contain unique values across all rows in the table.

public function unique(?string $columns = null): self

Parameters:

ParameterTypeDescription
$columns?stringThe column names to apply the index on, separated by commas (e.g., column1,column2) (optional).

Return:

self - Return table class instance.


primary

Sets the column as PRIMARY KEY.This method designates the column as the primary key of the table, ensuring each row is uniquely identified by its values in this column.

public function primary(bool $constraint = false): self

Parameters:

ParameterTypeDescription
$constraintboolWhether to use a primary key constraint (default: false).

Return:

self - Return table class instance.

Throws:

*Example Usages:

Sets column as primary key: PRIMARY KEY (column_name).

$table->primary();

Sets column as primary key constraint: CONSTRAINT pk_table_name PRIMARY KEY (column_name).

$table->primary(true);

foreign

Define a foreign key relationship.

public function foreign(string $table, string $column, bool $constraint = false): self

Parameters:

ParameterTypeDescription
$tablestringThe name of the referenced table.
$columnstringThe column in the referenced table.
$constraintboolWhether to include a named constraint (default: false).

Return:

self - Returns the table class instance.


unsigned

Add UNSIGNED attribute to a column definition.For non-MySQL databases, a CHECK (column >= 0) constraint is used to enforce non-negative values.

public function unsigned(): self

Return:

self - Return table class instance.


comment

Sets a comment for the column.

public function comment(string $comment): self

Parameters:

ParameterTypeDescription
$commentstringThe comment to set.

Return:

self - Return table class instance.


virtual

Define a VIRTUAL generated column.

public function virtual(string $expression): self

Parameters:

ParameterTypeDescription
$expressionstringThe SQL expression defining the column's value.

Return:

self - Return table class instance.

*Example Usages:

This would create a virtual generated column that concatenates first_name and last_name.

$table->virtual("CONCAT(first_name, ' ', last_name)");

This would create a virtual generated column that computes quantity * price.

$table->virtual("quantity * price");

This would create a virtual generated column in Oracle that concatenates first_name and last_name.

$table->virtual("first_name || ' ' || last_name");

stored

Define a STORED generated column.

public function stored(string $expression): self

Parameters:

ParameterTypeDescription
$expressionstringThe SQL expression defining the column's value.

Return:

self - Returns the table class instance.

*Example Usages:

This would create a stored generated column that concatenates first_name and last_name.

$table->stored("CONCAT(first_name, ' ', last_name)");

This would create a stored generated column that computes quantity * price.

$table->stored("quantity * price");

mediaType

Sets the media type for the column.

public function mediaType(string $type): self

Parameters:

ParameterTypeDescription
$typestringThe media type to set.

Return:

self - Return table class instance.


browserDisplay

Sets browser display transformation for the column.

public function browserDisplay(string $type, ?array $option = null): self

Parameters:

ParameterTypeDescription
$typestringThe transformation type.
$option?array<array-key,mixed>Optional transformation option.

Return:

self - Return table class instance.


inputTransformation

Sets input transformation for the column.

public function inputTransformation(string $type, ?array $option = null): self

Parameters:

ParameterTypeDescription
$typestringThe transformation type.
$option?array<array-key,mixed>Optional transformation option.

Return:

self - Return table class instance.


first

Reorder column at the beginning.

public function first(): self

Return:

self - Return table class instance.


after

Reorder column after a specific column name.

public function after(string $column): self

Parameters:

ParameterTypeDescription
$columnstringThe column name to move after it.

Return:

self - Return table class instance.


Other Column Data Type Methods

These methods are used to add other types of column data types, with names derived from the corresponding SQL data types they represent.


varchar

Creates a VARCHAR column with optional length.

varchar(string $name, int|null $length = 255): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column (default: 255).

Return:

self - Return table class instance.


tinyInt

Creates a TINYINT column with optional length.

tinyInt(string $name, int|null $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


smallInt

Creates a SMALLINT column with optional length.

smallInt(string $name, int|null $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


mediumInt

Creates a MEDIUMINT column with optional length.

mediumInt(string $name, int|null $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


bigInt

Creates a BIGINT column with optional length.

bigInt(string $name, int|null $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$precisionintThe precision of the double (default: 10).
$scaleintThe scale of the double (default: 2).

Return:

self - Return table class instance.


real

Creates a REAL column with optional length.

real(string $name, int|null $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


bit

Creates a BIT column with optional length.

bit(string $name, int|null $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


boolean

Creates a BOOLEAN column, a synonym for TINYINT(1).

boolean(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


serial

Creates a SERIAL column, an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.

serial(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


char

Creates a CHAR column with optional length.

char(string $name, int|null $length = 255): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column (default: 255).

Return:

self - Return table class instance.


tinyText

Creates a TINYTEXT column.

tinyText(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


mediumText

Creates a MEDIUMTEXT column.

mediumText(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


longText

Creates a LONGTEXT column.

longText(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


binary

Creates a BINARY column with optional length.

binary(string $name, int|null $length = 255): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column (default: 255).

Return:

self - Return table class instance.


varBinary

Creates a VARBINARY column with optional length.

varBinary(string $name, int|null $length = 255): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column (default: 255).

Return:

self - Return table class instance.


tinyBlob

Creates a TINYBLOB column with optional length.

tinyBlob(string $name, int|null $length = null): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.
$lengthint|nullThe optional length of the column.

Return:

self - Return table class instance.


blob

Creates a BLOB column.

blob(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


mediumBlob

Creates a MEDIUMBLOB column.

mediumBlob(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


longBlob

Creates a LONGBLOB column.

longBlob(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


geometry

Creates a GEOMETRY column.

geometry(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


point

Creates a POINT column.

point(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


lineString

Creates a LINESTRING column.

lineString(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


polygon

Creates a POLYGON column.

polygon(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


multiPoint

Creates a MULTIPOINT column.

multiPoint(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


multiLineString

Creates a MULTILINESTRING column.

multiLineString(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


multiPolygon

Creates a MULTIPOLYGON column.

multiPolygon(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


geometryCollection

Creates a GEOMETRYCOLLECTION column.

geometryCollection(string $name): self

Parameters:

ParameterTypeDescription
$namestringThe name of the column.

Return:

self - Return table class instance.


extra

Define an extra column options that will be added to the table definition.

public function extra(string $query): self

Parameters:

ParameterTypeDescription
$querystringThe entry query string to add.

Return:

self - Returns the table class instance.