yiisoft/yii-db-migration

Yii Db Migration

dev-master / 1.0.x-dev 2021-11-26 19:45 UTC

This package is auto-updated.

Last update: 2021-11-26 19:46:40 UTC


README

68747470733a2f2f796969736f66742e6769746875622e696f2f646f63732f696d616765732f7969695f6c6f676f2e737667

Yii Db Migration


The package implementing migration for yiisoft/db.

Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

Installation

The package could be installed via composer:

composer require yiisoft/yii-db-migration --prefer-dist

Note: You must install the repository of the implementation to use.

Example:

composer require yiisoft/db-sqlite --prefer-dist

Requirements

  • PHP 7.4 or higher.
  • Filter PHP extension.

Configuration

Example using yiisoft/app.

Di-Container:

Create config/common/db.php with content:

<?php

declare(strict_types=1);

use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\Connection as SqliteConnection;

return [
    ConnectionInterface::class => [
        'class' => SqliteConnection::class,
        '__construct()' => [
            'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'
        ]
    ]
];

Add to config/params.php:

...
'yiisoft/yii-db-migration' => [
    'createNamespace' => 'App\\Migration',
    'updateNamespace' => ['App\\Migration'],
],
...

Now the MigrationService::class uses the View of the application that is already registered in yiisoft/view.

Execute composer du in console config its rebuild.

Now we have the yiisoft/yii-db-migration package configured and it can be called in the console.

View the list of available commands execute in console: ./yii list

Available commands:
  database/list    Lists all tables in the database.
  migrate/create  Generate migration template.
  help             Displays help for a command
  list             Lists commands
  migrate/down     Downgrades the application by reverting old migrations.
  migrate/history  Displays the migration history.
  migrate/new      Displays the first 10 new migrations.
  migrate/redo     Redoes the last few migrations.
  migrate/up       Upgrades the application by applying new migrations.
  serve            Runs PHP built-in web server

Help simple command execute in console ./yii migrate/create --help.

Description:
  Generate migration template.

Usage:
  migrate/create [options] [--] <name>

Arguments:
  name                         Table name for generate migration.

Options:
  -c, --command[=COMMAND]      Command to execute. [default: "create"]
  -f, --fields[=FIELDS]        To create table fields right away
      --and[=AND]              And junction
      --namespace[=NAMESPACE]  Namespace migration
  -h, --help                   Display this help message
  -q, --quiet                  Do not output any message
  -V, --version                Display this application version
      --ansi                   Force ANSI output
      --no-ansi                Disable ANSI output
  -n, --no-interaction         Do not ask any interactive question
  -v|vv|vvv, --verbose         Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  This command Generate migration template

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework. To run it:

./vendor/bin/infection

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

License

The Yii Db Migration is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.