Skip to content

mabentley85/yii-db-migration

 
 

Repository files navigation

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 8.0 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

Testing

Unit testing

The package is tested with PHPUnit. For tests need PostgreSQL database with configuration:

  • host: 127.0.0.1
  • port: 5432
  • name: testdb
  • user: postgres
  • password: postgres

To run tests:

./vendor/bin/phpunit

Mutation testing

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

./vendor/bin/roave-infection-static-analysis-plugin

Static analysis

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

./vendor/bin/psalm

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.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

About

The package implementing migration for yiisoft/db.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%