yiisoft / yii-db-migration
Yii DB Migration
Fund package maintenance!
Open Collective
yiisoft
Installs: 26 624
Dependents: 5
Suggesters: 0
Security: 0
Stars: 20
Watchers: 15
Forks: 14
Open Issues: 28
Requires
- php: ^8.0
- ext-filter: *
- symfony/console: ^6.0
- yiisoft/aliases: ^1.1|^2.0|^3.0
- yiisoft/arrays: ^2.0|^3.0
- yiisoft/db: ^1.0
- yiisoft/files: ^1.0|^2.0
- yiisoft/injector: ^1.0
- yiisoft/strings: ^2.0
- yiisoft/yii-console: ^1.0|^2.0
Requires (Dev)
- maglnet/composer-require-checker: ^4.2
- phpunit/phpunit: ^9.5
- rector/rector: ^0.15.23
- roave/infection-static-analysis-plugin: ^1.18
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^4.30|^5.9
- yiisoft/db-pgsql: ^1.0
- yiisoft/db-sqlite: ^1.0
- yiisoft/di: ^1.0
- yiisoft/test-support: ^3.0
This package is auto-updated.
Last update: 2023-06-04 07:23:24 UTC
README
Yii DB Migration
The package implementing migration for yiisoft/db.
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', 'updateNamespaces' => ['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:
yiitest
- user:
root
- password:
root
Docker Image
To easily set up a pre-configured PostgreSQL instance for testing you can use the docker-compose.yml file in this repository.
For running the docker containers you can use the following command:
docker compose up -d
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.