Download the PHP package georgeff/schema without Composer
On this page you can find all versions of the php package georgeff/schema. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download georgeff/schema
More information about georgeff/schema
Files in georgeff/schema
Package schema
Short Description Database schema builder — driver-agnostic blueprints compiled to SQL for MySQL, PostgreSQL, and SQLite
License MIT
Informations about the package schema
georgeff/schema
Database schema builder for PHP. Define table structures using a fluent blueprint API and compile them to SQL for MySQL, PostgreSQL, or SQLite. Produces raw SQL strings — no connection required.
Installation
Overview
georgeff/schema separates schema definition from execution. You build a Blueprint, pass it to a compiler, and receive an array of SQL strings to run however you like.
Compilers
Three compilers are available, each implementing CompilerInterface:
Both MySQLCompiler and PostgreSQLCompiler accept optional constructor arguments:
Compiler Methods
create(Blueprint $blueprint): string[]
Returns one or more SQL statements to create the table. MySQL always returns a single statement with indexes inline. PostgreSQL and SQLite return additional CREATE INDEX statements when non-primary indexes are present.
drop(string $table, bool $ifExists = false): string
tableExists(): string
Returns a parameterized SQL query that checks whether a table exists. Pass the table name as a bound parameter when executing — do not interpolate it directly.
The query shape varies by driver:
- MySQL: queries
information_schema.tablesscoped toDATABASE() - PostgreSQL: queries
information_schema.tablesscoped to the configured schema (defaultpublic) - SQLite: queries
sqlite_master
alter(Blueprint $blueprint): string[]
Returns one statement per change. Used for adding/dropping columns, indexes, and foreign keys on an existing table.
SQLite limitation: SQLite only supports
ADD COLUMNandDROP COLUMN. Calls todropIndex(),dropForeign(), andforeign()on a Blueprint passed toSQLiteCompiler::alter()are silently ignored.
Blueprint
Column Types
| Method | Description |
|---|---|
id(string $name = 'id') |
BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY |
bigInteger(string $name) |
8-byte integer |
integer(string $name) |
4-byte integer |
smallInteger(string $name) |
2-byte integer |
tinyInteger(string $name) |
1-byte integer (MySQL) / SMALLINT (PostgreSQL) |
float(string $name) |
Floating point |
decimal(string $name, int $precision = 8, int $scale = 2) |
Fixed precision |
string(string $name, int $length = 255) |
VARCHAR |
char(string $name, int $length = 1) |
Fixed-length string |
text(string $name) |
Unbounded text |
boolean(string $name) |
Boolean (TINYINT(1) on MySQL, BOOLEAN on PostgreSQL, INTEGER on SQLite) |
json(string $name) |
JSON (TEXT on SQLite) |
uuid(string $name) |
UUID (CHAR(36) on MySQL, UUID on PostgreSQL, TEXT on SQLite) |
date(string $name) |
Date |
time(string $name) |
Time |
timestamp(string $name) |
Timestamp (TEXT on SQLite) |
timestamps() |
Adds nullable created_at and updated_at timestamp columns |
Column Modifiers
Modifiers chain off any column factory method:
defaultRaw() emits the provided string directly into the DDL without quoting — use it for SQL functions and expressions:
Warning:
defaultRaw()must never be called with user-supplied input. It is intended for developer-authored migration files only.
| Modifier | Description |
|---|---|
nullable(bool $value = true) |
Allows NULL; pass false to revert |
unsigned() |
UNSIGNED (MySQL only; ignored on PostgreSQL and SQLite) |
default(mixed $value) |
Sets a default value |
defaultRaw(string $sql) |
Sets a raw SQL expression as the default — emitted unquoted |
incrementing() |
AUTO_INCREMENT (MySQL) / SERIAL/BIGSERIAL (PostgreSQL) / AUTOINCREMENT (SQLite) |
primary(?string $name = null) |
Marks column as primary key |
unique(?string $name = null) |
Adds a unique index |
index(?string $name = null) |
Adds a regular index |
Foreign Keys
An optional constraint name can be passed as the second argument to foreign():
Valid actions for onDelete and onUpdate: NO ACTION, RESTRICT, SET NULL, CASCADE. Both default to RESTRICT.
ALTER Operations
Index Naming
When no name is provided, indexes are auto-named using the pattern:
Where suffix is primary, unique, index, or foreign. For example:
Pass an explicit name to override:
Driver Differences
| Feature | MySQL | PostgreSQL | SQLite |
|---|---|---|---|
| Quoting | Backticks | Double quotes | Double quotes |
| Auto-increment | AUTO_INCREMENT |
SERIAL / BIGSERIAL |
INTEGER PRIMARY KEY AUTOINCREMENT |
| Unsigned columns | Supported | Silently ignored | Silently ignored |
| Boolean | TINYINT(1) |
BOOLEAN |
INTEGER |
| UUID | CHAR(36) |
UUID |
TEXT |
Indexes in CREATE TABLE |
Inline | Separate statements | Separate statements |
ALTER foreign key support |
Yes | Yes | No |
tableExists source |
information_schema + DATABASE() |
information_schema + configured schema |
sqlite_master |