-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs folder standardization and other fixes (#257)
- Loading branch information
1 parent
c9f4ac9
commit 8de2712
Showing
11 changed files
with
221 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Yii DB Migration | ||
|
||
- [Yii Console](usage-with-yii-console.md) | ||
- [Symfony application](usage-with-symfony.md) | ||
- [Standalone](usage-standalone.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Yii DB Migration | ||
|
||
- [Yii Console](usage-with-yii-console.md) | ||
- [Symfony application](usage-with-symfony.md) | ||
- [Standalone](usage-standalone.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Standalone usage | ||
|
||
## With configuration file | ||
|
||
1. Copy configuration file `./vendor/yiisoft/db-migration/bin/yii-db-migration.php` to root folder of your project: | ||
|
||
```shell | ||
cp ./vendor/yiisoft/db-migration/bin/yii-db-migration.php ./yii-db-migration.php | ||
``` | ||
|
||
2. Define DB connection in configuration file (see | ||
[Yii DB documentation](https://github.com/yiisoft/db/blob/master/docs/en/README.md#create-connection)). | ||
For example, MySQL connection: | ||
|
||
```php | ||
'db' => new \Yiisoft\Db\Mysql\Connection( | ||
new \Yiisoft\Db\Mysql\Driver('mysql:host=mysql;dbname=mydb', 'user', 'q1w2e3r4'), | ||
new \Yiisoft\Db\Cache\SchemaCache(new \Yiisoft\Cache\ArrayCache()), | ||
), | ||
``` | ||
|
||
3. Optionally, modify other options in the configuration file. Each option has a comment with description. | ||
4. Run the console command without arguments to see the list of available migration commands: | ||
|
||
```shell | ||
./vendor/bin/yii-db-migration | ||
``` | ||
|
||
## Without configuration file | ||
|
||
This can be useful in testing environment and/or when multiple RDBMS are used. | ||
|
||
Configure all dependencies manually: | ||
|
||
```php | ||
use Yiisoft\Db\Connection\ConnectionInterface; | ||
use Yiisoft\Db\Migration\Informer\NullMigrationInformer; | ||
use Yiisoft\Db\Migration\Migrator; | ||
use Yiisoft\Db\Migration\Service\MigrationService; | ||
use Yiisoft\Injector\Injector; | ||
/** @var ConnectionInterface $database */ | ||
$migrator = new Migrator($database, new NullMigrationInformer()); | ||
$migrationService = new MigrationService($database, new Injector(), $migrator); | ||
$migrationService->setSourcePaths([dirname(__DIR__, 2), 'migrations']); | ||
``` | ||
Then initialize the command for using without CLI. For example, for applying migrations it will be `UpdateCommand`: | ||
```php | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Yiisoft\Db\Migration\Command\UpdateCommand; | ||
use Yiisoft\Db\Migration\Runner\UpdateRunner; | ||
$command = new UpdateCommand(new UpdateRunner($migrator), $migrationService, $migrator); | ||
$command->setHelperSet(new HelperSet(['queestion' => new QuestionHelper()])); | ||
``` | ||
And, finally, run the command: | ||
```php | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
$input = new ArrayInput([]); | ||
$input->setInteractive(false); | ||
$this->getMigrateUpdateCommand()->run($input, new NullOutput()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Usage with Symfony | ||
|
||
Require migrations and DB driver. Let's use SQLite for this example: | ||
|
||
```shell | ||
composer require yiisoft/db-migration | ||
composer require yiisoft/db-sqlite | ||
``` | ||
|
||
Configure migrations and database connection in your `config/services.yml`: | ||
|
||
```yaml | ||
Yiisoft\Db\Migration\: | ||
resource: '../vendor/yiisoft/db-migration/src/' | ||
|
||
Yiisoft\Db\Migration\Informer\MigrationInformerInterface: | ||
class: 'Yiisoft\Db\Migration\Informer\ConsoleMigrationInformer' | ||
|
||
Yiisoft\Injector\Injector: | ||
arguments: | ||
- '@service_container' | ||
|
||
Yiisoft\Db\Migration\Service\MigrationService: | ||
calls: | ||
- setNewMigrationNamespace: ['App\Migrations'] | ||
- setNewMigrationPath: [''] | ||
- setSourceNamespaces: [['App\Migrations']] | ||
- setSourcePaths: [[]] | ||
|
||
Yiisoft\Db\: | ||
resource: '../vendor/yiisoft/db/src/' | ||
exclude: | ||
- '../vendor/yiisoft/db/src/Debug/' | ||
|
||
cache.app.simple: | ||
class: 'Symfony\Component\Cache\Psr16Cache' | ||
arguments: | ||
- '@cache.app' | ||
|
||
Yiisoft\Db\Cache\SchemaCache: | ||
arguments: | ||
- '@cache.app.simple' | ||
|
||
Yiisoft\Db\Connection\ConnectionInterface: | ||
class: '\Yiisoft\Db\Sqlite\Connection' | ||
arguments: | ||
- '@sqlite_driver' | ||
|
||
sqlite_driver: | ||
class: '\Yiisoft\Db\Sqlite\Driver' | ||
arguments: | ||
- 'sqlite:./var/migrations.sq3' | ||
``` | ||
That's it. Now you can use `bin/console migrate:*` commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Usage with Yii Console | ||
|
||
In this example, we use [yiisoft/app](https://github.com/yiisoft/app). | ||
|
||
First, configure DI container. Create `config/common/db.php` with the following content: | ||
|
||
```php | ||
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`: | ||
|
||
```php | ||
... | ||
'yiisoft/db-migration' => [ | ||
'newMigrationNamespace' => 'App\\Migration', | ||
'sourceNamespaces' => ['App\\Migration'], | ||
], | ||
... | ||
``` | ||
|
||
Now the `MigrationService::class` uses the `View` of the application that is already registered in `yiisoft/view`. | ||
|
||
Execute `composer du` in console to rebuild the configuration. | ||
|
||
Now we have the `yiisoft/db-migration` package configured and it can be called in the console. | ||
|
||
View the list of available commands with `./yii list`: | ||
|
||
```shell | ||
./yii list | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters