src/Schema.php
public function alterTable($table, callable $callback)
    {
        if (!$this->hasTable($table)) {
            throw new Exception("Table $table exist.");
        }

        $builder      = new TableBuilder();
        call_user_func_array($callback, [ &$builder ]);
        $tableBuilder = $builder->buildFull();
        $schema       = $this->getSchema();
        $dataTable    = $this->read($this->path, $table);
        $fields       = $schema[ $table ][ 'fields' ];

        foreach ($tableBuilder as $key => $value) {
            /* Si un champ est ajouté il ne doit pas exister dans le schéma. */
            if (!isset($value[ 'opt' ]) && isset($fields[ $key ])) {
                throw new Exception("Field $key already exists in table $table.");
            }
            /* Si un champ est modifie il doit exister dans le schéma. */
            if (isset($value[ 'opt' ]) && $value[ 'opt' ] === 'modify' && !isset($fields[ $key ])) {
                throw new ColumnsNotFoundException("$key field does not exists in table $table.");
            }
            /* Si il s'agit d'une opération sur un champ il doit exister dans le schéma. */
            if (isset($value[ 'opt' ]) && !isset($fields[ $value[ 'name' ] ])) {
                throw new ColumnsNotFoundException("$key field does not exists in table $table.");
            }

            if (!isset($value[ 'opt' ])) {
                if ($value[ 'type' ] === 'increments') {
                    throw new ColumnsValueException("Table $table can not have multiple incremental values.");
                }
                $fields[ $key ] = $value;
                foreach ($dataTable as &$data) {
                    $data[ $key ] = self::getValueDefault($key, $value);
                }
            } elseif ($value[ 'opt' ] === 'rename') {
                $tmp                      = $fields[ $value[ 'name' ] ];
                unset($fields[ $value[ 'name' ] ]);
                $fields[ $value[ 'to' ] ] = $tmp;

                foreach ($dataTable as $key => &$data) {
                    $tmp                                 = $data[ $value[ 'name' ] ];
                    unset($data[ $value[ 'name' ] ]);
                    $dataTable[ $key ][ $value[ 'to' ] ] = $tmp;
                }
            } elseif ($value[ 'opt' ] === 'modify') {
                unset($value[ 'name' ], $value[ 'opt' ]);
                $fields[ $key ] = $value;

                foreach ($dataTable as &$data) {
                    $data[ $key ] = self::getValueDefault($key, $value);
                }
            } elseif ($value[ 'opt' ] === 'drop') {
                unset($fields[ $value[ 'name' ] ]);

                foreach ($dataTable as $key => $data) {
                    unset($dataTable[ $key ][ $value[ 'name' ] ]);
                }
            }
        }

        $schema[ $table ][ 'fields' ] = $fields;
        $this->save($this->path, $this->name, $schema);
        $this->save($this->path, $table, $dataTable);
        $this->reloadSchema();

        return $this;
    }
public function alterTable($table, callable $callback)
    {
        if (!$this->hasTable($table)) {
            throw new Exception("Table $table exist.");
        }

        $builder      = new TableBuilder();
        call_user_func_array($callback, [ &$builder ]);
        $tableBuilder = $builder->buildFull();
        $schema       = $this->getSchema();
        $dataTable    = $this->read($this->path, $table);
        $fields       = $schema[ $table ][ 'fields' ];

        foreach ($tableBuilder as $key => $value) {
            /* Si un champ est ajouté il ne doit pas exister dans le schéma. */
            if (!isset($value[ 'opt' ]) && isset($fields[ $key ])) {
                throw new Exception("Field $key already exists in table $table.");
            }
            /* Si un champ est modifie il doit exister dans le schéma. */
            if (isset($value[ 'opt' ]) && $value[ 'opt' ] === 'modify' && !isset($fields[ $key ])) {
                throw new ColumnsNotFoundException("$key field does not exists in table $table.");
            }
            /* Si il s'agit d'une opération sur un champ il doit exister dans le schéma. */
            if (isset($value[ 'opt' ]) && !isset($fields[ $value[ 'name' ] ])) {
                throw new ColumnsNotFoundException("$key field does not exists in table $table.");
            }

            if (!isset($value[ 'opt' ])) {
                if ($value[ 'type' ] === 'increments') {
                    throw new ColumnsValueException("Table $table can not have multiple incremental values.");
                }
                $fields[ $key ] = $value;
                foreach ($dataTable as &$data) {
                    $data[ $key ] = self::getValueDefault($key, $value);
                }
            } elseif ($value[ 'opt' ] === 'rename') {
                $tmp                      = $fields[ $value[ 'name' ] ];
                unset($fields[ $value[ 'name' ] ]);
                $fields[ $value[ 'to' ] ] = $tmp;

                foreach ($dataTable as $key => &$data) {
                    $tmp                                 = $data[ $value[ 'name' ] ];
                    unset($data[ $value[ 'name' ] ]);
                    $dataTable[ $key ][ $value[ 'to' ] ] = $tmp;
                }
            } elseif ($value[ 'opt' ] === 'modify') {
                unset($value[ 'name' ], $value[ 'opt' ]);
                $fields[ $key ] = $value;

                foreach ($dataTable as &$data) {
                    $data[ $key ] = self::getValueDefault($key, $value);
                }
            } elseif ($value[ 'opt' ] === 'drop') {
                unset($fields[ $value[ 'name' ] ]);

                foreach ($dataTable as $key => $data) {
                    unset($dataTable[ $key ][ $value[ 'name' ] ]);
                }
            }
        }

        $schema[ $table ][ 'fields' ] = $fields;
        $this->save($this->path, $this->name, $schema);
        $this->save($this->path, $table, $dataTable);
        $this->reloadSchema();

        return $this;
    }
Modifie les champs du schéma de données.

@param string        $table    Nom de la table.
@param callable|null $callback fonction(TableBuilder $table) pour créer les champs.

@throws TableNotFoundException
@throws Exception
@return $this