Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename config options #247

Merged
merged 7 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bin/yii-db-migration
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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']],

Check warning on line 17 in config/di-console.php

View check run for this annotation

Codecov / codecov/patch

config/di-console.php#L14-L17

Added lines #L14 - L17 were not covered by tests
],

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

'yiisoft/db-migration' => [
'createNamespace' => '',
'createPath' => '',
'updateNamespaces' => [],
'updatePaths' => [],
'newMigrationNamespace' => '',
'newMigrationPath' => '',
'sourceNamespaces' => [],
'sourcePaths' => [],

Check warning on line 28 in config/params.php

View check run for this annotation

Codecov / codecov/patch

config/params.php#L25-L28

Added lines #L25 - L28 were not covered by tests
],
];
8 changes: 4 additions & 4 deletions docs/en/usage-with-symfony.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading
Loading