2017 © Pedro Peláez
 

library schema

Agile Schema

image

atk4/schema

Agile Schema

  • Thursday, July 12, 2018
  • by romaninsh
  • Repository
  • 4 Watchers
  • 2 Stars
  • 2,844 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 17 Versions
  • 15 % Grown

The README.md

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., (*1)

Build Status Code Climate StyleCI CodeCov Test Coverage Issue Count, (*2)

License GitHub release, (*3)

Basic Usage:

``` php // Add the following code on your setup page / wizard:, (*4)

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


The user will see a console which would adjust database to contain required tables / fields for the models: ![migrator-console](docs/migrator-console.png) Of course it's also possible to perform migration without visual feedback: ``` php $changes = (\atk4\schema\Migration::getMigration(new User($app->db)))->migrate();

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

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

// or alter $migration = \atk4\schema\Migration::getMigration($app->db); $migration->table('user') ->newField('age', ['type'=>'integer']) ->alter();, (*8)


Currently we fully support MySQL and SQLite connections, partly PgSQL and Oracle connections. Other SQL databases are not yet supported. Field declaration uses same types as [ATK Data](https://github.com/atk4/data). ## Examples `schema\Migration` is a simple class for building schema-related queries using DSQL. ``` php <?php $m = \atk4\data\schema\Migration::getMigration($connection); $m->table('user')->drop(); $m->field('id'); $m->field('name', ['type'=>'string']); $m->field('age', ['type'=>'integer']); $m->field('bio'); $m->create();

schema\Snapshot (NOT IMPLEMENTED) is a simple class that can record and restore table contents:, (*9)

``` php <?php $s = new \atk4\data\schema\Snapshot($connection); $tables = $s->getDB($tables);, (*10)

// do anything with tables, (*11)

$s->setDB($tables);, (*12)


## Integration with PHPUnit You can now automate your database testing by setting and checking your database contents easier. First, extend your test-script from `\atk4\schema\PHPUnit_SchemaTestCase`. Next, you need to set your schema ``` php $q = ['user' => [ ['name' => 'John', 'surname' => 'Smith'], ['name' => 'Steve', 'surname' => 'Jobs'], ]]; $this->setDB($q);

Perform any changes, then execute:, (*13)

$this->assertEquals($q, $this->getDB('user'));

To ensure that database remained the same. Of course you can compare against any other state., (*14)

  • Automatically add 'id' field by default
  • Create tables for you
  • Detect types (int, string, date, boolean etc)
  • Hides ID values if you don't pass them

Installation

Add the following inside your composer.json file:, (*15)

console composer require atk4/schema, (*16)

Current Status

Stable functionality, (*17)

The Versions

12/07 2018

dev-develop

dev-develop http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

12/07 2018

dev-feature/fix-alter-field

dev-feature/fix-alter-field http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

08/05 2018

dev-feature/model-integration

dev-feature/model-integration http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

19/04 2018

1.1.4

1.1.4.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

10/04 2018

1.1.3

1.1.3.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

07/04 2018

1.1.2

1.1.2.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

07/04 2018

dev-master

9999999-dev http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

07/04 2018

1.1.1

1.1.1.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

04/04 2018

dev-release/1.1.0

dev-release/1.1.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

04/04 2018

1.1.0

1.1.0.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

22/03 2018

dev-feature/some_changes_for_tests

dev-feature/some_changes_for_tests http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

12/04 2017

dev-release/1.0.2

dev-release/1.0.2 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

12/04 2017

1.0.2

1.0.2.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

12/04 2017

dev-release/1.0.1

dev-release/1.0.1 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

12/04 2017

1.0.1

1.0.1.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

30/09 2016

1.0

1.0.0.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter

30/09 2016

0.1

0.1.0.0 http://github.com/atk4/schema

Agile Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

sql framework schema migration data agile alter