PHPackages                             fyre/forge - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. fyre/forge

ActiveLibrary[Database &amp; ORM](/categories/database)

fyre/forge
==========

A database forge library.

v6.0(7mo ago)01843MITPHP

Since Jun 12Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/elusivecodes/FyreForge)[ Packagist](https://packagist.org/packages/fyre/forge)[ RSS](/packages/fyre-forge/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (6)Versions (38)Used By (3)

FyreForge
=========

[](#fyreforge)

**FyreForge** is a free, open-source database forge library for *PHP*.

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Methods](#methods)
- [Forges](#forges)
    - [MySQL Forges](#mysql-forges)
    - [Postgres Forges](#postgres-forges)
    - [Sqlite Forges](#sqlite-forges)
- [Table](#tables)
    - [MySQL Tables](#mysql-tables)
    - [Postgres Tables](#postgres-tables)
    - [Sqlite Tables](#sqlite-tables)
- [Columns](#columns)
    - [MySQL Columns](#mysql-columns)
- [Indexes](#indexes)
- [Foreign Keys](#foreign-keys)

Installation
------------

[](#installation)

**Using Composer**

```
composer require fyre/forge

```

In PHP:

```
use Fyre\Forge\ForgeRegistry;
```

Basic Usage
-----------

[](#basic-usage)

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$forgeRegistry = new ForgeRegistry($container);
```

**Autoloading**

It is recommended to bind the *ForgeRegistry* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```
$container->singleton(ForgeRegistry::class);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$forgeRegistry = $container->use(ForgeRegistry::class);
```

Methods
-------

[](#methods)

**Map**

Map a [*Connection*](https://github.com/elusivecodes/FyreDB#connections) class to a [*Forge*](#forges) handler.

- `$connectionClass` is a string representing the [*Connection*](https://github.com/elusivecodes/FyreDB#connections) class name.
- `$forgeClass` is a string representing the [*Forge*](#forges) class name.

```
$forgeRegistry->map($connectionClass, $forgeClass);
```

**Use**

Load the shared [*Forge*](#forges) for a [*Connection*](https://github.com/elusivecodes/FyreDB#connections).

- `$connection` is a [*Connection*](https://github.com/elusivecodes/FyreDB#connections).

```
$forge = $forgeRegistry->use($connection);
```

[*Forge*](#forges) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).

Forges
------

[](#forges)

**Add Column**

Add a column to a table.

- `$tableName` is a string representing the table name.
- `$columnName` is a string representing the column name.
- `$options` is an array containing the column options.
    - `type` is a string representing the column type, and will default to `StringType::class`.
    - `length` is a number representing the column length, and will default to the type default.
    - `precision` is a number representing the column precision, and will default to the type default.
    - `nullable` is a boolean indicating whether the column is nullable, and will default to *false*.
    - `default` is a string representing the column default value, and will default to *null* (no default).
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column, and will default to *false*.

```
$forge->addColumn($tableName, $columnName, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

Additional column options may be available depending on the connection handler.

**Add Foreign Key**

Add a foreign key to a table.

- `$tableName` is a string representing the table name.
- `$foreignKeyName` is a string representing the foreign key name.
- `$options` is an array containing the foreign key options.
    - `columns` is a string or array containing the columns to use for the foreign key, and will default to the foreign key name.
    - `referencedTable` is a string representing the referenced table to use.
    - `referencedColumns` is a string or array containing the columns to use in the referenced table.
    - `onUpdate` is a string containing the ON UPDATE operation, and will default to *null*.
    - `onDelete` is a string containing the ON DELETE operation, and will default to *null*.

```
$forge->addForeignKey($tableName, $foreignKeyName, $options);
```

Foreign keys cannot be added to an existing Sqlite table.

**Add Index**

Add an index to a table.

- `$tableName` is a string representing the table name.
- `$indexName` is a string representing the index name.
- `$options` is an array containing the index options.
    - `columns` is a string or array containing the columns to use for the index, and will default to the index name.
    - `unique` is a boolean indicating whether the index must be unique, and will default to *false*.
    - `primary` is a boolean indicating whether the index is a primary key, and will default to *false*.

```
$forge->addIndex($tableName, $indexName, $options);
```

Additional index options may be available depending on the connection handler.

Primary keys cannot be added to an existing Sqlite table.

**Alter Table**

Alter a table.

- `$tableName` is a string representing the table name.
- `$options` is an array containing the table options.

```
$forge->alterTable($tableName, $options);
```

Additional table options may be available depending on the connection handler.

**Build**

Build a [*Table*](#tables).

- `$tableName` is a string representing the table name.
- `$options` is an array containing the table options.

```
$table = $forge->build($tableName, $options);
```

[*Table*](#tables) dependencies will be resolved automatically from the Container.

Additional table options may be available depending on the connection handler.

**Create Table**

Create a new table.

- `$tableName` is a string representing the table name.
- `$columns` is an array containing the column definitions.
- `$indexes` is an array containing the index definitions.
- `$foreignKeys` is an array containing the foreign key definitions.
- `$options` is an array containing the schema options.

```
$forge->createTable($tableName, $columns, $indexes, $foreignKeys, $options);
```

Additional table options may be available depending on the connection handler.

**Drop Column**

Drop a column from a table.

- `$tableName` is a string representing the table name.
- `$columnName` is a string representing the column name.

```
$forge->dropColumn($tableName, $columnName);
```

**Drop Foreign Key**

Drop a foreign key from a table.

- `$tableName` is a string representing the table name.
- `$foreignKeyName` is a string representing the foreign key name.

```
$forge->dropForeignKey($tableName, $foreignKeyName);
```

Foreign keys cannot be dropped from an existing Sqlite table.

**Drop Index**

Drop an index from a table.

- `$tableName` is a string representing the table name.
- `$indexName` is a string representing the index name.

```
$forge->dropIndex($tableName, $indexName);
```

Primary keys cannot be dropped from an existing Sqlite table.

**Drop Table**

Drop a table.

- `$tableName` is a string representing the table name.

```
$forge->dropTable($tableName, $options);
```

**Get Connection**

Get the [*Connection*](https://github.com/elusivecodes/FyreDB#connections).

```
$connection = $forge->getConnection();
```

**Rename Column**

Rename a column.

- `$tableName` is a string representing the table name.
- `$columnName` is a string representing the column name.
- `$newColumnName` is a string representing the new column name.

```
$forge->renameColumn($tableName, $columnName, $newColumnName);
```

**Rename Table**

Rename a table.

- `$tableName` is a string representing the table name.
- `$newTableName` is a string representing the new table name.

```
$forge->renameTable($tableName, $newTableName);
```

### MySQL Forges

[](#mysql-forges)

The [*MySQL*](https://github.com/elusivecodes/FyreDB#MySQL) Forge extends the *Forge* class and provides additional methods and options specific to MySQL databases.

**Add Column**

Add a column to a table.

- `$tableName` is a string representing the table name.
- `$columnName` is a string representing the column name.
- `$options` is an array containing the column options.
    - `type` is a string representing the column type, and will default to `StringType::class`.
    - `length` is a number representing the column length, and will default to the type default.
    - `precision` is a number representing the column precision, and will default to the type default.
    - `values` is an array containing the enum/set values, and will default to *null*.
    - `nullable` is a boolean indicating whether the column is nullable, and will default to *false*.
    - `unsigned` is a boolean indicating whether the column is unsigned, and will default to *false*.
    - `default` is a string representing the column default value, and will default to *null* (no default).
    - `charset` is a string representing the column character set, and will default to the connection character set.
    - `collation` is a string representing the column collation, and will default to the connection collation.
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column, and will default to *false*.
    - `comment` is a string representing the column comment, and will default to "".
    - `after` is a string representing the column to add this column after, and will default to *null*.
    - `first` is a boolean indicating whether to add this column first in the table, and will default to *false*.

```
$forge->addColumn($tableName, $columnName, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

**Add Index**

Add an index to a table.

- `$tableName` is a string representing the table name.
- `$indexName` is a string representing the index name.
- `$options` is an array containing the index options.
    - `columns` is a string or array containing the columns to use for the index, and will default to the index name.
    - `type` is a string representing the index type, and will default to "*BTREE*".
    - `unique` is a boolean indicating whether the index must be unique, and will default to *false*.
    - `primary` is a boolean indicating whether the index is a primary key, and will default to *false*.

```
$forge->addIndex($tableName, $indexName, $options);
```

**Alter Table**

Alter a table.

- `$tableName` is a string representing the table name.
- `$options` is an array containing the table options.
    - `engine` is a string representing the table engine, and will default to "*InnoDB*".
    - `charset` is a string representing the table character set, and will default to the connection character set.
    - `collation` is a string representing the table collation, and will default to the connection collation.
    - `comment` is a string representing the table comment, and will default to "".

```
$forge->alterTable($tableName, $options);
```

**Build**

Build a [*Table*](#tables).

- `$tableName` is a string representing the table name.
- `$options` is an array containing the table options.
    - `engine` is a string representing the table engine, and will default to "*InnoDB*".
    - `charset` is a string representing the table character set, and will default to the connection character set.
    - `collation` is a string representing the table collation, and will default to the connection collation.
    - `comment` is a string representing the table comment, and will default to "".

```
$table = $forge->build($tableName, $options);
```

[*Table*](#tables) dependencies will be resolved automatically from the Container.

**Change Column**

Change a table column.

- `$tableName` is a string representing the table name.
- `$columnName` is a string representing the column name.
- `$options` is an array containing the column options.
    - `name` is a string representing the new column name.
    - `type` is a string representing the column type.
    - `length` is a number representing the column length.
    - `precision` is a number representing the column precision.
    - `values` is an array containing the enum/set values.
    - `nullable` is a boolean indicating whether the column is nullable.
    - `unsigned` is a boolean indicating whether the column is unsigned.
    - `default` is a string representing the column default value.
    - `charset` is a string representing the column character set.
    - `collation` is a string representing the column collation.
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column.
    - `comment` is a string representing the column comment.
    - `after` is a string representing the column to add this column after.
    - `first` is a boolean indicating whether to add this column first in the table.

```
$forge->changeColumn($tableName, $columnName, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

Unspecified options will default to the current value.

**Create Schema**

Create a new schema.

- `$schema` is a string representing the schema name.
- `$options` is an array containing the schema options.
    - `charset` is a string representing the schema character set, and will default to the connection character set.
    - `collation` is a string representing the schema collation, and will default to the connection collation.
    - `ifNotExists` is a boolean indicating whether to use an `IF NOT EXISTS` clause, and will default to *false*.

```
$forge->createSchema($schema, $options);
```

**Create Table**

Create a new table.

- `$table` is a string representing the table name.
- `$columns` is an array containing the column definitions.
- `$indexes` is an array containing the index definitions.
- `$foreignKeys` is an array containing the foreign key definitions.
- `$options` is an array containing the schema options.
    - `engine` is a string representing the table engine, and will default to "*InnoDB*".
    - `charset` is a string representing the table character set, and will default to the connection character set.
    - `collation` is a string representing the table collation, and will default to the connection collation.
    - `comment` is a string representing the table comment, and will default to "".

```
$forge->createTable($table, $columns, $indexes, $foreignKeys, $options);
```

**Drop Primary Key**

Drop a primary key from a table.

- `$tableName` is a string representing the table name.

```
$forge->dropPrimaryKey($tableName);
```

**Drop Schema**

Drop a schema.

- `$schema` is a string representing the schema name.
- `$options` is an array containing the schema options.
    - `ifExists` is a boolean indicating whether to use an `IF EXISTS` clause, and will default to *false*.

```
$forge->dropSchema($schema, $options);
```

### Postgres

[](#postgres)

The [*Postgres*](https://github.com/elusivecodes/FyreDB#Postgres) Forge extends the *Forge* class and provides additional methods and options specific to Postgres databases.

**Add Column**

Add a column to a table.

- `$tableName` is a string representing the table name.
- `$columnName` is a string representing the column name.
- `$options` is an array containing the column options.
    - `type` is a string representing the column type, and will default to `StringType::class`.
    - `length` is a number representing the column length, and will default to the type default.
    - `precision` is a number representing the column precision, and will default to the type default.
    - `nullable` is a boolean indicating whether the column is nullable, and will default to *false*.
    - `default` is a string representing the column default value, and will default to *null* (no default).
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column, and will default to *false*.
    - `comment` is a string representing the column comment, and will default to "".

```
$forge->addColumn($tableName, $columnName, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

**Alter Table**

Alter a table.

- `$tableName` is a string representing the table name.
- `$options` is an array containing the table options.
    - `comment` is a string representing the table comment, and will default to "".

```
$forge->alterTable($tableName, $options);
```

**Build**

Build a [*Table*](#tables).

- `$tableName` is a string representing the table name.
- `$options` is an array containing the table options.
    - `comment` is a string representing the table comment, and will default to "".

```
$table = $forge->build($tableName, $options);
```

[*Table*](#tables) dependencies will be resolved automatically from the Container.

**Change Column**

Change a table column.

- `$tableName` is a string representing the table name.
- `$columnName` is a string representing the column name.
- `$options` is an array containing the column options.
    - `name` is a string representing the new column name.
    - `type` is a string representing the column type.
    - `length` is a number representing the column length.
    - `precision` is a number representing the column precision.
    - `nullable` is a boolean indicating whether the column is nullable.
    - `default` is a string representing the column default value.
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column.
    - `comment` is a string representing the column comment.

```
$forge->changeColumn($tableName, $columnName, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

Unspecified options will default to the current value.

**Create Schema**

Create a new schema.

- `$schema` is a string representing the schema name.
- `$options` is an array containing the schema options.
    - `ifNotExists` is a boolean indicating whether to use an `IF NOT EXISTS` clause, and will default to *false*.

```
$forge->createSchema($schema, $options);
```

**Create Table**

Create a new table.

- `$table` is a string representing the table name.
- `$columns` is an array containing the column definitions.
- `$indexes` is an array containing the index definitions.
- `$foreignKeys` is an array containing the foreign key definitions.
- `$options` is an array containing the schema options.
    - `comment` is a string representing the table comment, and will default to "".

```
$forge->createTable($tableName, $columns, $indexes, $foreignKeys, $options);
```

**Drop Primary Key**

Drop a primary key from a table.

- `$tableName` is a string representing the table name.

```
$forge->dropPrimaryKey($tableName);
```

**Drop Schema**

Drop a schema.

- `$schema` is a string representing the schema name.
- `$options` is an array containing the schema options.
    - `ifExists` is a boolean indicating whether to use an `IF EXISTS` clause, and will default to *false*.

```
$forge->dropSchema($schema, $options);
```

### Sqlite

[](#sqlite)

The [*Sqlite*](https://github.com/elusivecodes/FyreDB#Sqlite) Forge extends the *Forge* class.

**Add Column**

Add a column to a table.

- `$tableName` is a string representing the table name.
- `$columnName` is a string representing the column name.
- `$options` is an array containing the column options.
    - `type` is a string representing the column type, and will default to `StringType::class`.
    - `length` is a number representing the column length, and will default to the type default.
    - `precision` is a number representing the column precision, and will default to the type default.
    - `nullable` is a boolean indicating whether the column is nullable, and will default to *false*.
    - `unsigned` is a boolean indicating whether the column is unsigned, and will default to *false*.
    - `default` is a string representing the column default value, and will default to *null* (no default).
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column, and will default to *false*.

```
$forge->addColumn($tableName, $columnName, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

Tables
------

[](#tables)

**Add Column**

Add a column to the table.

- `$column` is a string representing the column name.
- `$options` is an array containing the column options.
    - `name` is a string representing the new column name, and will default to the column name.
    - `type` is a string representing the column type, and will default to `StringType::class`.
    - `length` is a number representing the column length, and will default to the type default.
    - `precision` is a number representing the column precision, and will default to the type default.
    - `nullable` is a boolean indicating whether the column is nullable, and will default to *false*.
    - `default` is a string representing the column default value, and will default to *null* (no default).
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column, and will default to *false*.

```
$table->addColumn($column, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

Additional column options may be available depending on the connection handler.

**Add Foreign Key**

Add a foreign key to the table.

- `$foreignKey` is a string representing the foreign key name.
- `$options` is an array containing the foreign key options.
    - `columns` is a string or array containing the columns to use for the foreign key, and will default to the foreign key name.
    - `referencedTable` is a string representing the referenced table to use.
    - `referencedColumns` is a string or array containing the columns to use in the referenced table.
    - `onUpdate` is a string containing the ON UPDATE operation, and will default to *null*.
    - `onDelete` is a string containing the ON DELETE operation, and will default to *null*.

```
$table->addForeignKey($foreignKey, $options);
```

Foreign keys cannot be added to an existing Sqlite table.

**Add Index**

Add an index to the table.

- `$index` is a string representing the index name.
- `$options` is an array containing the index options.
    - `columns` is a string or array containing the columns to use for the index, and will default to the index name.
    - `unique` is a boolean indicating whether the index must be unique, and will default to *false*.
    - `primary` is a boolean indicating whether the index is a primary key, and will default to *false*.

```
$table->addIndex($index, $options);
```

Additional index options may be available depending on the connection handler.

Primary keys cannot be added to an existing Sqlite table.

**Change Column**

Change a table column.

- `$column` is a string representing the column name.
- `$options` is an array containing the column options.
    - `name` is a string representing the new column name, and will default to the column name.

```
$table->changeColumn($column, $options);
```

Additional column options may be available depending on the connection handler.

Column definitions can not be modified for an existing Sqlite table.

**Clear**

Clear the column and index data.

```
$table->clear();
```

**Column**

Get a [*Column*](#columns).

- `$name` is a string representing the column name.

```
$column = $table->column($name);
```

**Column Names**

Get the names of all table columns.

```
$columnNames = $table->columnNames();
```

**Columns**

Get all table [columns](#columns).

```
$columns = $table->columns();
```

**Drop**

Drop the table.

```
$table->drop();
```

**Drop Column**

Drop a column from the table.

- `$column` is a string representing the column name.

```
$table->dropColumn($column);
```

**Drop Foreign Key**

Drop a foreign key from the table.

- `$foreignKey` is a string representing the foreign key name.

```
$table->dropForeignKey($foreignKey);
```

Foreign keys cannot be dropped from an existing Sqlite table.

**Drop Index**

Drop an index from the table.

- `$index` is a string representing the index name.

```
$table->dropIndex($index);
```

Primary keys cannot be dropped from an existing Sqlite table.

**Execute**

Generate and execute the SQL queries.

```
$table->execute();
```

**Foreign Key**

Get a table [*ForeignKey*](#foreign-keys).

- `$name` is a string representing the foreign key name.

```
$foreignKey = $table->foreignKey($name);
```

**Foreign Keys**

Get all table [foreign keys](#foreign-keys).

```
$foreignKeys = $table->foreignKeys();
```

**Get Comment**

Get the table comment.

```
$comment = $table->getComment();
```

**Get Forge**

Get the [*Forge*](#forges).

```
$forge = $table->getForge();
```

**Get Name**

Get the table name.

```
$name = $table->getName();
```

**Has Column**

Determine whether the table has a column.

- `$name` is a string representing the column name.

```
$hasColumn = $table->hasColumn($name);
```

**Has Foreign Key**

Determine whether the table has a foreign key.

- `$name` is a string representing the foreign key name.

```
$hasForeignKey = $table->hasForeignKey($name);
```

**Has Index**

Determine whether the table has an index.

- `$name` is a string representing the index name.

```
$hasIndex = $table->hasIndex($name);
```

**Index**

Get a table [*Index*](#indexes).

- `$name` is a string representing the index name.

```
$index = $table->index($name);
```

**Indexes**

Get all table [indexes](#indexes).

```
$indexes = $table->indexes();
```

**Rename**

Rename the table.

- `$table` is a string representing the new table name.

```
$table->rename($table);
```

**Set Primary Key**

Set the primary key.

- `$columns` is a string or array containing the columns to use for the primary key.

```
$table->setPrimaryKey($columns);
```

Primary keys cannot be added to an existing Sqlite table.

**SQL**

Generate the SQL queries.

```
$queries = $table->sql();
```

**To Array**

Get the table data as an array.

```
$data = $table->toArray();
```

### MySQL Tables

[](#mysql-tables)

**Add Column**

Add a column to the table.

- `$column` is a string representing the column name.
- `$options` is an array containing the column options.
    - `type` is a string representing the column type, and will default to `StringType::class`.
    - `length` is a number representing the column length, and will default to the type default.
    - `precision` is a number representing the column precision, and will default to the type default.
    - `values` is an array containing the enum/set values, and will default to *null*.
    - `nullable` is a boolean indicating whether the column is nullable, and will default to *false*.
    - `unsigned` is a boolean indicating whether the column is unsigned, and will default to *false*.
    - `default` is a string representing the column default value, and will default to *null* (no default).
    - `charset` is a string representing the column character set, and will default to the connection character set.
    - `collation` is a string representing the column collation, and will default to the connection collation.
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column, and will default to *false*.
    - `comment` is a string representing the column comment, and will default to "".
    - `after` is a string representing the column to add this column after, and will default to *null*.
    - `first` is a boolean indicating whether to add this column first in the table, and will default to *false*.

```
$table->addColumn($column, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

**Add Index**

Add an index to the table.

- `$index` is a string representing the index name.
- `$options` is an array containing the index options.
    - `columns` is a string or array containing the columns to use for the index, and will default to the index name.
    - `type` is a string representing the index type, and will default to "*BTREE*".
    - `unique` is a boolean indicating whether the index must be unique, and will default to *false*.
    - `primary` is a boolean indicating whether the index is a primary key, and will default to *false*.

```
$table->addIndex($index, $options);
```

**Change Column**

Change a table column.

- `$column` is a string representing the column name.
- `$options` is an array containing the column options.
    - `name` is a string representing the new column name.
    - `type` is a string representing the column type.
    - `length` is a number representing the column length.
    - `precision` is a number representing the column precision.
    - `values` is an array containing the enum/set values.
    - `nullable` is a boolean indicating whether the column is nullable.
    - `unsigned` is a boolean indicating whether the column is unsigned.
    - `default` is a string representing the column default value.
    - `charset` is a string representing the column character set.
    - `collation` is a string representing the column collation.
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column.
    - `comment` is a string representing the column comment.
    - `after` is a string representing the column to add this column after.
    - `first` is a boolean indicating whether to add this column first in the table.

```
$table->changeColumn($column, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

Unspecified options will default to the current value.

**Get Charset**

Get the table character set.

```
$charset = $table->getCharset();
```

**Get Collation**

Get the table collation.

```
$collation = $table->getCollation();
```

**Get Engine**

Get the table engine.

```
$engine = $table->getEngine();
```

### Postgres Tables

[](#postgres-tables)

**Add Column**

Add a column to the table.

- `$column` is a string representing the column name.
- `$options` is an array containing the column options.
    - `type` is a string representing the column type, and will default to `StringType::class`.
    - `length` is a number representing the column length, and will default to the type default.
    - `precision` is a number representing the column precision, and will default to the type default.
    - `nullable` is a boolean indicating whether the column is nullable, and will default to *false*.
    - `default` is a string representing the column default value, and will default to *null* (no default).
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column, and will default to *false*.
    - `comment` is a string representing the column comment, and will default to "".

```
$table->addColumn($column, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

**Add Index**

Add an index to the table.

- `$index` is a string representing the index name.
- `$options` is an array containing the index options.
    - `columns` is a string or array containing the columns to use for the index, and will default to the index name.
    - `type` is a string representing the index type, and will default to "*BTREE*".
    - `unique` is a boolean indicating whether the index must be unique, and will default to *false*.
    - `primary` is a boolean indicating whether the index is a primary key, and will default to *false*.

```
$table->addIndex($index, $options);
```

**Change Column**

Change a table column.

- `$column` is a string representing the column name.
- `$options` is an array containing the column options.
    - `name` is a string representing the new column name.
    - `type` is a string representing the column type.
    - `length` is a number representing the column length.
    - `precision` is a number representing the column precision.
    - `nullable` is a boolean indicating whether the column is nullable.
    - `default` is a string representing the column default value.
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column.
    - `comment` is a string representing the column comment.

```
$table->changeColumn($column, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

Unspecified options will default to the current value.

### Sqlite Tables

[](#sqlite-tables)

**Add Column**

Add a column to the table.

- `$column` is a string representing the column name.
- `$options` is an array containing the column options.
    - `type` is a string representing the column type, and will default to `StringType::class`.
    - `length` is a number representing the column length, and will default to the type default.
    - `precision` is a number representing the column precision, and will default to the type default.
    - `nullable` is a boolean indicating whether the column is nullable, and will default to *false*.
    - `unsigned` is a boolean indicating whether the column is unsigned, and will default to *false*.
    - `default` is a string representing the column default value, and will default to *null* (no default).
    - `autoIncrement` is a boolean indicating whether the column is an an auto incrementing column, and will default to *false*.

```
$table->addColumn($column, $options);
```

You can also specify a [*Type*](https://github.com/elusivecodes/FyreTypeParser#types) class name as the `type`, which will be automatically mapped to the correct type.

Columns
-------

[](#columns)

**Get Comment**

Get the column comment.

```
$comment = $column->getComment();
```

**Get Default**

Get the column default value.

```
$default = $column->getDefault();
```

**Get Length**

Get the column length.

```
$length = $column->getLength();
```

**Get Name**

Get the column name.

```
$name = $column->getName();
```

**Get Precision**

Get the column precision.

```
$precision = $column->getPrecision();
```

**Get Table**

Get the [*Table*](#tables).

```
$table = $column->getTable();
```

**Get Type**

Get the column type.

```
$type = $column->getType();
```

**Is Auto Increment**

Determine whether the column is an auto increment column.

```
$isAutoIncrement = $column->isAutoIncrement();
```

**Is Nullable**

Determine whether the column is nullable.

```
$isNullable = $column->isNullable();
```

**Is Unsigned**

Determine whether the column is unsigned.

```
$isUnsigned = $column->isUnsigned();
```

**To Array**

Get the column data as an array.

```
$data = $column->toArray();
```

### MySQL Columns

[](#mysql-columns)

**Get Charset**

Get the column character set.

```
$charset = $column->getCharset();
```

**Get Collation**

Get the column collation.

```
$collation = $column->getCollation();
```

**Get Values**

Get the column enum values.

```
$values = $column->getValues();
```

Indexes
-------

[](#indexes)

**Get Columns**

Get the column names.

```
$columns = $index->getColumns();
```

**Get Name**

Get the index name.

```
$name = $index->getName();
```

**Get Table**

Get the [*Table*](#tables).

```
$table = $index->getTable();
```

**Get Type**

Get the index type.

```
$type = $index->getType();
```

**Is Primary**

Determine whether the index is primary.

```
$isPrimary = $index->isPrimary();
```

**Is Unique**

Determine whether the index is unique.

```
$isUnique = $index->isUnique();
```

**To Array**

Get the index data as an array.

```
$data = $index->toArray();
```

Foreign Keys
------------

[](#foreign-keys)

**Get Columns**

Get the column names.

```
$columns = $foreignKey->getColumns();
```

**Get Name**

```
$name = $foreignKey->getName();
```

**Get On Delete**

Get the delete action.

```
$onDelete = $foreignKey->getOnDelete();
```

**Get On Update**

Get the update action.

```
$onUpdate = $foreignKey->getOnUpdate();
```

**Get Referenced Columns**

Get the referenced column names.

```
$referencedColumn = $foreignKey->getReferencedColumns();
```

**Get Referenced Table**

Get the referenced table name.

```
$referencedTable = $foreignKey->getReferencedTable();
```

**Get Table**

Get the [*Table*](#tables).

```
$table = $foreignKey->getTable();
```

**To Array**

Get the foreign key data as an array.

```
$data = $foreignKey->toArray();
```

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance63

Regular maintenance activity

Popularity10

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~34 days

Recently: every ~50 days

Total

37

Last Release

228d ago

Major Versions

v1.0.3 → v2.02023-07-29

v2.0.4 → v3.02023-12-17

v3.1.1 → v4.02024-08-10

v4.0.5 → v5.02024-11-06

v5.1.3 → v6.02025-11-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/fad81fd5941e3a637c8a5749d05ae3ed9314d5e2fee57f59c3d9ec3b41259c6b?d=identicon)[elusivecodes](/maintainers/elusivecodes)

---

Top Contributors

[![elusivecodes](https://avatars.githubusercontent.com/u/18050480?v=4)](https://github.com/elusivecodes "elusivecodes (41 commits)")

---

Tags

databaseforgephpschema

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/fyre-forge/health.svg)

```
[![Health](https://phpackages.com/badges/fyre-forge/health.svg)](https://phpackages.com/packages/fyre-forge)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
