PHPackages                             atk4/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. [Framework](/categories/framework)
4. /
5. atk4/schema

AbandonedArchivedLibrary[Framework](/categories/framework)

atk4/schema
===========

Agile Schema

2.3.1(5y ago)6104.2k↑1250%5[7 issues](https://github.com/atk4/schema/issues)6MITPHPPHP &gt;=7.3.0

Since Sep 30Pushed 5y ago7 watchersCompare

[ Source](https://github.com/atk4/schema)[ Packagist](https://packagist.org/packages/atk4/schema)[ Docs](http://github.com/atk4/schema)[ RSS](/packages/atk4-schema/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (30)Used By (6)

!!! repo was integrated into atk4/data !!!
==========================================

[](#-repo-was-integrated-into-atk4data-)

==============================

[](#httpsgithubcomatk4data)

Agile Data - SQL Schema Management Add-on
=========================================

[](#agile-data---sql-schema-management-add-on)

This extension for Agile Data implements ability to work with SQL schema, execute migrations, perform DB-tests in PHPUnit (used by other ATK frameworks) and sync up "Model" structure to the database.

[![Build](https://github.com/atk4/schema/workflows/Unit%20Testing/badge.svg)](https://github.com/atk4/schema/workflows/Unit%20Testing/badge.svg)[![CodeCov](https://camo.githubusercontent.com/e515d3bf99ed12afd296988242fb3a6df51c4d652742e2a44a5fc0a69f7d61c0/68747470733a2f2f636f6465636f762e696f2f67682f61746b342f736368656d612f6272616e63682f646576656c6f702f67726170682f62616467652e737667)](https://codecov.io/gh/atk4/schema)[![GitHub release](https://camo.githubusercontent.com/53835e2f8a88c90d485bfd20331ddb8fe8a84d2e178c39cec0a2085064df9193/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f61746b342f736368656d612e737667)](CHANGELOG.md)[![Code Climate](https://camo.githubusercontent.com/3cbcbecb879d25ba4a404301aeaf7e367ff3b842b5240c2af6bf287ff16e75e5/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f61746b342f736368656d612f6261646765732f6770612e737667)](https://codeclimate.com/github/atk4/schema)

### Basic Usage:

[](#basic-usage)

```
// Add the following code on your setup page / wizard:

$app->add('MigratorConsole')
    ->migrateModels([
        new Model\User($app->db),
        new Model\Order($app->db),
        new Model\Payment($app->db)
    ]);
```

The user will see a console which would adjust database to contain required tables / fields for the models:

[![migrator-console](docs/migrator-console.png)](docs/migrator-console.png)

Of course it's also possible to perform migration without visual feedback:

```
$changes = \atk4\schema\Migration::of(new User($app->db))->run();
```

If you need a more fine-graned migration, you can define them in great detail.

```
// create table
$migrator = \atk4\schema\Migration::of($app->db);
$migrator->table('user')
    ->id()
    ->field('name')
    ->field('address', ['type'=>'text']);
    ->create();

// or alter
$migrator = \atk4\schema\Migration::of($app->db);
$migrator->table('user')
    ->newField('age', ['type'=>'integer'])
    ->alter();
```

Currently atk4/schema fully supports MySQL and SQLite databases and partly PostgreSQL and Oracle. Other SQL databases are not yet natively supported but you can register your migrator class at runtime.

```
// $dbDriver is the connection driver name
// MyCustomMigrator::class should be extending \atk4\schema\Migration

\atk4\schema\Migration::register($platformClass, MyCustomMigrator::class);
```

Field declaration uses same types as [ATK Data](https://github.com/atk4/data).

Examples
--------

[](#examples)

`schema\Migration` is a simple class for building schema-related queries using DSQL.

```
