Skip to content

Commit

Permalink
Rename config options (#247)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Rogachev <arogachev90@gmail.com>
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
  • Loading branch information
3 people committed Dec 21, 2023
1 parent e0e4e49 commit f99d3b3
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 185 deletions.
16 changes: 8 additions & 8 deletions bin/yii-db-migration
Expand Up @@ -35,10 +35,10 @@ require $_composer_autoload_path ?? $rootPath . '/vendor/autoload.php';
* historyTable: string,
* migrationNameLimit: int|null,
* maxSqlOutputLength: int|null,
* createNamespace: string,
* createPath: string,
* updateNamespaces: list<string>,
* updatePaths: list<string>,
* newMigrationNamespace: string,
* newMigrationPath: string,
* sourceNamespaces: list<string>,
* sourcePaths: list<string>,
* } $params
*/
$params = require $rootPath . '/yii-db-migration.php';
Expand All @@ -60,10 +60,10 @@ $downRunner = new DownRunner($migrator);
$updateRunner = new UpdateRunner($migrator);

$migrationService = new MigrationService($aliases, $db, $injector, $migrator);
$migrationService->setCreateNamespace($params['createNamespace']);
$migrationService->setCreatePath($params['createPath']);
$migrationService->setUpdateNamespaces($params['updateNamespaces']);
$migrationService->setUpdatePaths($params['updatePaths']);
$migrationService->setNewMigrationNamespace($params['newMigrationNamespace']);
$migrationService->setNewMigrationPath($params['newMigrationPath']);
$migrationService->setSourceNamespaces($params['sourceNamespaces']);
$migrationService->setSourcePaths($params['sourcePaths']);

$application = new Application('Yii Database Migration Tool', '1.0.0');
$application->addCommands([
Expand Down
17 changes: 9 additions & 8 deletions bin/yii-db-migration.php
Expand Up @@ -20,24 +20,25 @@
/**
* Namespace of new migration classes.
*/
'createNamespace' => '',
'newMigrationNamespace' => '',

/**
* List of namespaces containing the migration classes.
*/
'updateNamespaces' => [],
'sourceNamespaces' => [],

/**
* Path to the directory for new migration classes. This path is used when you are using migrations without
* namespaces.
*/
'createPath' => '',
'newMigrationPath' => '',

/**
* List of directories containing the migration classes. Migration classes located at this paths should be declared
* without a namespace. Use "updateNamespaces" option in case you are using namespaced migrations.
* List of directories containing the migration classes.
* Migration classes located at these paths should be declared without a namespace.
* Use the "sourceNamespaces" option in case you are using namespaced migrations.
*/
'updatePaths' => [],
'sourcePaths' => [],

/**
* The name of the database table for storing migration history information.
Expand All @@ -51,7 +52,7 @@

/**
* Indicates whether the table names generated should consider the `tablePrefix` setting of the DB connection.
* For example, if the table name is `post` the generator will return `{{%post}}`.
* For example, if the table name is `post`, the generator will return `{{%post}}`.
*/
'useTablePrefix' => true,

Expand All @@ -61,7 +62,7 @@
'container' => null,

/**
* The maximum length of a SQL output in console.
* The maximum length of an SQL output in console.
*/
'maxSqlOutputLength' => null,
];
8 changes: 4 additions & 4 deletions config/di-console.php
Expand Up @@ -11,10 +11,10 @@
return [
MigrationService::class => [
'class' => MigrationService::class,
'setCreateNamespace()' => [$params['yiisoft/db-migration']['createNamespace']],
'setUpdateNamespaces()' => [$params['yiisoft/db-migration']['updateNamespaces']],
'setCreatePath()' => [$params['yiisoft/db-migration']['createPath']],
'setUpdatePaths()' => [$params['yiisoft/db-migration']['updatePaths']],
'setNewMigrationNamespace()' => [$params['yiisoft/db-migration']['newMigrationNamespace']],
'setSourceNamespaces()' => [$params['yiisoft/db-migration']['sourceNamespaces']],
'setNewMigrationPath()' => [$params['yiisoft/db-migration']['newMigrationPath']],
'setSourcePaths()' => [$params['yiisoft/db-migration']['sourcePaths']],
],

MigrationInformerInterface::class => ConsoleMigrationInformer::class,
Expand Down
8 changes: 4 additions & 4 deletions config/params.php
Expand Up @@ -22,9 +22,9 @@
],

'yiisoft/db-migration' => [
'createNamespace' => '',
'createPath' => '',
'updateNamespaces' => [],
'updatePaths' => [],
'newMigrationNamespace' => '',
'newMigrationPath' => '',
'sourceNamespaces' => [],
'sourcePaths' => [],
],
];
8 changes: 4 additions & 4 deletions docs/en/usage-with-symfony.md
Expand Up @@ -25,10 +25,10 @@ Yiisoft\Injector\Injector:

Yiisoft\Db\Migration\Service\MigrationService:
calls:
- setCreateNamespace: ['App\Migrations']
- setCreatePath: ['']
- setUpdateNamespaces: [['App\Migrations']]
- setUpdatePaths: [[]]
- setNewMigrationNamespace: ['App\Migrations']
- setNewMigrationPath: ['']
- setSourceNamespaces: [['App\Migrations']]
- setSourcePaths: [[]]

Yiisoft\Db\:
resource: '../vendor/yiisoft/db/src/'
Expand Down
4 changes: 2 additions & 2 deletions docs/en/usage-with-yii-console.md
Expand Up @@ -27,8 +27,8 @@ Add to `config/params.php`:
```php
...
'yiisoft/db-migration' => [
'createNamespace' => 'App\\Migration',
'updateNamespaces' => ['App\\Migration'],
'newMigrationNamespace' => 'App\\Migration',
'sourceNamespaces' => ['App\\Migration'],
],
...
```
Expand Down
21 changes: 11 additions & 10 deletions src/Command/CreateCommand.php
Expand Up @@ -29,14 +29,14 @@
*
* This command creates a new migration using the available migration template.
*
* To use it, configure migrations paths (`createPath` and `updatePaths`) in `params.php` file, in your application.
* To use it, configure migrations paths (`newMigrationPath` and `sourcePaths`) in `params.php` file, in your application.
*
* ```php
* 'yiisoft/db-migration' => [
* 'createNamespace' => '',
* 'createPath' => '',
* 'updateNamespaces' => [],
* 'updatePaths' => [],
* 'newMigrationNamespace' => '',
* 'newMigrationPath' => '',
* 'sourceNamespaces' => [],
* 'sourcePaths' => [],
* ],
* ```
*
Expand All @@ -47,7 +47,7 @@
* ./yii migrate:create table --command=table
* ```
*
* In order to generate a namespaced migration, you should specify a namespace before the migration's name.
* To generate a namespaced migration, you should specify a namespace before the migration's name.
*
* Note that backslash (`\`) is usually considered a special character in the shell, so you need to escape it properly
* to avoid shell errors or incorrect behavior.
Expand All @@ -59,7 +59,8 @@
* ./yii migrate:create post --command=table --path=@root/migrations/blog
* ```
*
* In case {@see $createPath} is not set and no namespace is provided, {@see $createNamespace} will be used.
* In case {@see MigrationService::$newMigrationPath} is not set, and no namespace is provided,
* {@see MigrationService::$newMigrationNamespace} will be used.
*/
#[AsCommand('migrate:create', 'Creates a new migration.')]
final class CreateCommand extends Command
Expand Down Expand Up @@ -101,10 +102,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$namespace = $input->getOption('namespace');

if ($path !== null || $namespace !== null) {
$this->migrationService->setCreatePath((string) $path);
$this->migrationService->setCreateNamespace((string) $namespace);
$this->migrationService->setNewMigrationPath((string) $path);
$this->migrationService->setNewMigrationNamespace((string) $namespace);
} else {
$namespace = $this->migrationService->getCreateNamespace();
$namespace = $this->migrationService->getNewMigrationNamespace();
}

if ($this->migrationService->before(self::getDefaultName() ?? '') === Command::INVALID) {
Expand Down
4 changes: 2 additions & 2 deletions src/Command/NewCommand.php
Expand Up @@ -66,8 +66,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$namespaces = $input->getOption('namespace');

if (!empty($paths) || !empty($namespaces)) {
$this->migrationService->setUpdatePaths($paths);
$this->migrationService->setUpdateNamespaces($namespaces);
$this->migrationService->setSourcePaths($paths);
$this->migrationService->setSourceNamespaces($namespaces);
}

$this->migrationService->before(self::getDefaultName() ?? '');
Expand Down
4 changes: 2 additions & 2 deletions src/Command/UpdateCommand.php
Expand Up @@ -70,8 +70,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$namespaces = $input->getOption('namespace');

if (!empty($paths) || !empty($namespaces)) {
$this->migrationService->setUpdatePaths($paths);
$this->migrationService->setUpdateNamespaces($namespaces);
$this->migrationService->setSourcePaths($paths);
$this->migrationService->setSourceNamespaces($namespaces);
}

if ($this->migrationService->before(self::getDefaultName() ?? '') === Command::INVALID) {
Expand Down
4 changes: 2 additions & 2 deletions src/MigrationBuilder.php
Expand Up @@ -178,9 +178,9 @@ public function delete(string $table, array|string $condition = '', array $param
}

/**
* Builds and executes a SQL statement for creating a new DB table.
* Builds and executes an SQL statement for creating a new DB table.
*
* The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name
* The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name
* stands for a column name which will be properly quoted by the method, and definition stands for the column type
* which can contain an abstract DB type.
*
Expand Down

0 comments on commit f99d3b3

Please sign in to comment.