Skip to content

Commit

Permalink
Fix docs (#261)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergei Predvoditelev <[email protected]>
  • Loading branch information
luizcmarin and vjik authored May 19, 2024
1 parent 1212ef4 commit 83f35d8
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 13 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<a href="https://github.com/yiisoft" target="_blank">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px" alt="Yii">
</a>
<h1 align="center">Yii DB Migration</h1>
<br>
Expand All @@ -18,12 +18,14 @@ Yii DB Migration allows you to manage database schema using migrations.

Supports the following databases out of the box:

- [MSSQL](https://www.microsoft.com/en-us/sql-server/sql-server-2019) of versions **2017, 2019, 2022**.
- [MySQL](https://www.mysql.com/) of versions **5.7–8.0**.
- [MariaDB](https://mariadb.org/) of versions **10.4–10.9**.
- [Oracle](https://www.oracle.com/database/) of versions **12c–21c**.
- [PostgreSQL](https://www.postgresql.org/) of versions **9.6–15**.
- [SQLite](https://www.sqlite.org/index.html) of version **3.3 and above**.
| DBMS | Version |
|----|----------|
| [MSSQL](https://www.microsoft.com/en-us/sql-server/sql-server-2019) | **2017, 2019, 2022** |
| [MySQL](https://www.mysql.com/) | **5.7–8.0** |
| [MariaDB](https://mariadb.org/) | **10.4–10.9** |
| [Oracle](https://www.oracle.com/database/) | **12c–21c** |
| [PostgreSQL](https://www.postgresql.org/) | **9.6–15** |
| [SQLite](https://www.sqlite.org) | **3.3 and above** |

## Requirements

Expand Down Expand Up @@ -53,7 +55,7 @@ The create command allows defining fields for the table being created.

## Documentation

- [Guide](docs/guide/en/README.md)
- Guide: [English](docs/guide/en/README.md), [Português - Brasil](docs/guide/pt-BR/README.md)
- [Internals](docs/internals.md)

If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
Expand Down
19 changes: 16 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/db-migration/issues?state=open",
"source": "https://github.com/yiisoft/db-migration",
"forum": "https://www.yiiframework.com/forum/",
"wiki": "https://www.yiiframework.com/wiki/",
"irc": "ircs://irc.libera.chat:6697/yii",
"chat": "https://t.me/yii3en",
"source": "https://github.com/yiisoft/db-migration"
"chat": "https://t.me/yii3en"
},
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/yiisoft"
},
{
"type": "github",
"url": "https://github.com/sponsors/yiisoft"
}
],
"require": {
"php": "^8.0",
"ext-filter": "*",
Expand Down Expand Up @@ -50,7 +60,10 @@
"Yiisoft\\Db\\Migration\\Tests\\": "tests",
"Yiisoft\\Db\\Migration\\Tests\\Support\\": "tests/Support",
"Yiisoft\\Db\\Migration\\Tests\\ForTest\\": "tests/Support",
"Yiisoft\\Db\\Migration\\Tests\\Support\\MigrationsExtra\\": ["tests/Support/MigrationsExtra", "tests/Support/MigrationsExtra2"]
"Yiisoft\\Db\\Migration\\Tests\\Support\\MigrationsExtra\\": [
"tests/Support/MigrationsExtra",
"tests/Support/MigrationsExtra2"
]
}
},
"extra": {
Expand Down
3 changes: 2 additions & 1 deletion docs/guide/en/usage-standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
```

2. Define DB connection in configuration file (see
[Yii DB documentation](https://github.com/yiisoft/db/blob/master/docs/en/README.md#create-connection)).
[Yii DB documentation](https://github.com/yiisoft/db/blob/master/docs/guide/en/README.md#create-connection)).
For example, MySQL connection:

```php
Expand All @@ -20,6 +20,7 @@
```

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
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/en/usage-with-symfony.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Usage with Symfony

Require migrations and DB driver. Let's use SQLite for this example:
Require migrations package and DB driver. Let's use SQLite for this example:

```shell
composer require yiisoft/db-migration
Expand Down
5 changes: 5 additions & 0 deletions docs/guide/pt-BR/README.md
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)
71 changes: 71 additions & 0 deletions docs/guide/pt-BR/usage-standalone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Standalone usage

## Com arquivo de configuração

1. Copie o arquivo de configuração `./vendor/yiisoft/db-migration/bin/yii-db-migration.php` para a pasta raiz do seu projeto:

```shell
cp ./vendor/yiisoft/db-migration/bin/yii-db-migration.php ./yii-db-migration.php
```

2. Defina a conexão do banco de dados no arquivo de configuração (consulte a
[documentação do Yii DB](https://github.com/yiisoft/db/blob/master/docs/en/README.md#create-connection)).
Por exemplo, conexão MySQL:

```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. Opcionalmente, modifique outras opções no arquivo de configuração. Cada opção possui um comentário com descrição.

4. Execute o comando do console sem argumentos para ver a lista de comandos de migração disponíveis:

```shell
./vendor/bin/yii-db-migration
```

## Sem arquivo de configuração

Isso pode ser útil em ambientes de teste e/ou quando vários RDBMS são usados.

Configure todas as dependências manualmente:

```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']);
```
Em seguida, inicialize o comando para usar sem CLI. Por exemplo, para aplicar migrações será `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()]));
```
E, por fim, execute o comando:
```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());
```
55 changes: 55 additions & 0 deletions docs/guide/pt-BR/usage-with-symfony.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Uso com Symfony

Requer [Yii DB Migration](https://github.com/yiisoft/db-migration) e driver de banco de dados. Vamos usar [Yii DB SQLite](https://github.com/yiisoft/db-sqlite) para este exemplo:

```shell
composer require yiisoft/db-migration
composer require yiisoft/db-sqlite
```

Configure migração e a conexão de banco de dados em seu `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'
```
É isso. Agora você pode usar os comandos `bin/console migrate:*`.
46 changes: 46 additions & 0 deletions docs/guide/pt-BR/usage-with-yii-console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Uso com Yii Console

Neste exemplo, usamos [yiisoft/app](https://github.com/yiisoft/app).

Primeiro, configure o contêiner DI. Crie `config/common/db.php` com o seguinte conteúdo:

```php
<?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'
]
]
];
```

Adicione em `config/params.php`:

```php
...
'yiisoft/db-migration' => [
'newMigrationNamespace' => 'App\\Migration',
'sourceNamespaces' => ['App\\Migration'],
],
...
```

Agora o `MigrationService::class` usa o `View` da aplicação que já está registrada em `yiisoft/view`.

Execute `composer du` no console para reconstruir a configuração.

Agora temos o pacote [`yiisoft/db-migration`](https://github.com/yiisoft/db-migration) configurado e ele pode ser chamado no console.

Veja a lista de comandos disponíveis com `./yii list`:

```shell
./yii list
```

0 comments on commit 83f35d8

Please sign in to comment.