PHPackages                             evopix/kohana-schema - 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. evopix/kohana-schema

AbandonedArchivedKohana-module[Database &amp; ORM](/categories/database)

evopix/kohana-schema
====================

This is a port of Laravels Schema library to Kohana. It provides a database agnostic way of manipulating tables. It works well with all of the databases supported by Doctrine DBAL, and has a unified API across all of these systems.

111.0k1PHP

Since May 8Pushed 10y ago1 watchersCompare

[ Source](https://github.com/evopix/kohana-schema)[ Packagist](https://packagist.org/packages/evopix/kohana-schema)[ RSS](/packages/evopix-kohana-schema/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

This is a port of Laravels Schema library to Kohana.
====================================================

[](#this-is-a-port-of-laravels-schema-library-to-kohana)

---

- [Introduction](#introduction)
- [Creating &amp; Dropping Tables](#creating-and-dropping-tables)
- [Adding Columns](#adding-columns)
- [Renaming Columns](#renaming-columns)
- [Dropping Columns](#dropping-columns)
- [Checking Existence](#checking-existence)
- [Adding Indexes](#adding-indexes)
- [Foreign Keys](#foreign-keys)
- [Dropping Indexes](#dropping-indexes)
- [Storage Engines](#storage-engines)

Introduction
------------

[](#introduction)

The Kohana `Schema` class provides a database agnostic way of manipulating tables. It works well with all of the databases supported by Kohana, and has a unified API across all of these systems.

Creating &amp; Dropping Tables
------------------------------

[](#creating--dropping-tables)

To create a new database table, the `Schema::create` method is used:

```
Schema::create('users', function($table)
{
	$table->increments('id');
});

```

The first argument passed to the `create` method is the name of the table, and the second is a `Closure` which will receive a `Blueprint` object which may be used to define the new table.

To rename an existing database table, the `rename` method may be used:

```
Schema::rename($from, $to);

```

To specify which connection the schema operation should take place on, pass a third parameter to the method:

```
Schema::create('users', function($table)
{
	$table->increments('id');
}, 'default');

```

To drop a table, you may use the `Schema::drop` method:

```
Schema::drop('users');

```

Adding Columns
--------------

[](#adding-columns)

To update an existing table, we will use the `Schema::table` method:

```
Schema::table('users', function($table)
{
	$table->string('email');
});

```

Modifying Columns
-----------------

[](#modifying-columns)

To modify columns in an existing table, we will use the `Schema::table` method:

```
Schema::table('users', function($table)
{
	$table->modify_column('email', 'string', ['length' => '50']);
});

```

> **Note:** Modifying columns is not supported in SQLite.

The table builder contains a variety of column types that you may use when building your tables:

CommandDescription`$table->big_increments('id');`Incrementing ID using a "big integer" equivalent.`$table->big_integer('votes');`BIGINT equivalent to the table`$table->binary('data');`BLOB equivalent to the table`$table->boolean('confirmed');`BOOLEAN equivalent to the table`$table->date('created_at');`DATE equivalent to the table`$table->datetime('created_at');`DATETIME equivalent to the table`$table->decimal('amount', 5, 2);`DECIMAL equivalent with a precision and scale`$table->double('column', 15, 8);`DOUBLE equivalent with precision`$table->enum('choices', array('foo', 'bar'));`ENUM equivalent to the table`$table->float('amount');`FLOAT equivalent to the table`$table->increments('id');`Incrementing ID to the table (primary key).`$table->integer('votes');`INTEGER equivalent to the table`$table->long_text('description');`LONGTEXT equivalent to the table`$table->medium_text('description');`MEDIUMTEXT equivalent to the table`$table->morphs('taggable');`Adds INTEGER `taggable_id` and STRING `taggable_type``$table->small_integer('votes');`SMALLINT equivalent to the table`$table->tiny_integer('numbers');`TINYINT equivalent to the table`$table->soft_deletes();`Adds **deleted\_at** column for soft deletes`$table->string('email');`VARCHAR equivalent column`$table->string('name', 100);`VARCHAR equivalent with a length`$table->text('description');`TEXT equivalent to the table`$table->time('sunrise');`TIME equivalent to the table`$table->timestamp('added_on');`TIMESTAMP equivalent to the table`$table->timestamps();`Adds **created\_at** and **updated\_at** columns`->nullable()`Designate that the column allows NULL values`->default($value)`Declare a default value for a column`->unsigned()`Set INTEGER to UNSIGNEDIf you are using the MySQL database, you may use the `after` method to specify the order of columns:

#### Using After On MySQL

[](#using-after-on-mysql)

```
$table->string('name')->after('email');

```

Renaming Columns
----------------

[](#renaming-columns)

To rename a column, you may use the `rename_column` method on the Schema builder. Before renaming a column, be sure to add the `doctrine/dbal` dependency to your `composer.json` file.

#### Renaming A Column

[](#renaming-a-column)

```
Schema::table('users', function($table)
{
	$table->rename_column('from', 'to');
});

```

> **Note:** Renaming `enum` column types is not supported.

Dropping Columns
----------------

[](#dropping-columns)

#### Dropping A Column From A Database Table

[](#dropping-a-column-from-a-database-table)

```
Schema::table('users', function($table)
{
	$table->drop_column('votes');
});

```

#### Dropping Multiple Columns From A Database Table

[](#dropping-multiple-columns-from-a-database-table)

```
Schema::table('users', function($table)
{
	$table->drop_column('votes', 'avatar', 'location');
});

```

Adding Indexes
--------------

[](#adding-indexes)

The schema builder supports several types of indexes. There are two ways to add them. First, you may fluently define them on a column definition, or you may add them separately:

#### Fluently Creating A Column And Index

[](#fluently-creating-a-column-and-index)

```
$table->string('email')->unique();

```

Or, you may choose to add the indexes on separate lines. Below is a list of all available index types:

CommandDescription`$table->primary('id');`Adding a primary key`$table->primary(array('first', 'last'));`Adding composite keys`$table->unique('email');`Adding a unique index`$table->index('state');`Adding a basic index

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

[](#foreign-keys)

Laravel also provides support for adding foreign key constraints to your tables:

#### Adding A Foreign Key To A Table

[](#adding-a-foreign-key-to-a-table)

```
$table->foreign('user_id')->references('id')->on('users');

```

In this example, we are stating that the `user_id` column references the `id` column on the `users` table.

You may also specify options for the "on delete" and "on update" actions of the constraint:

```
$table->foreign('user_id')
      ->references('id')->on('users')
      ->on_delete('cascade');

```

To drop a foreign key, you may use the `drop_foreign` method. A similar naming convention is used for foreign keys as is used for other indexes:

```
$table->drop_foreign('posts_user_id_foreign');

```

> **Note:** When creating a foreign key that references an incrementing integer, remember to always make the foreign key column `unsigned`.

Dropping Indexes
----------------

[](#dropping-indexes)

To drop an index you must specify the index's name. Laravel assigns a reasonable name to the indexes by default. Simply concatenate the table name, the names of the column in the index, and the index type. Here are some examples:

CommandDescription`$table->drop_primary('users_id_primary');`Dropping a primary key from the "users" table`$table->drop_unique('users_email_unique');`Dropping a unique index from the "users" table`$table->drop_index('geo_state_index');`Dropping a basic index from the "geo" table

Storage Engines
---------------

[](#storage-engines)

To set the storage engine for a table, set the `engine` property on the schema builder:

```
Schema::create('users', function($table)
{
    $table->engine = 'InnoDB';

    $table->string('email');
});

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

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

---

Top Contributors

[![evopix](https://avatars.githubusercontent.com/u/99371?v=4)](https://github.com/evopix "evopix (12 commits)")

### Embed Badge

![Health badge](/badges/evopix-kohana-schema/health.svg)

```
[![Health](https://phpackages.com/badges/evopix-kohana-schema/health.svg)](https://phpackages.com/packages/evopix-kohana-schema)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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