Skip to content

Commit 168ebe4

Browse files
author
Bizley
committed
proper names
1 parent bafab33 commit 168ebe4

File tree

5 files changed

+75
-248
lines changed

5 files changed

+75
-248
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 17 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -78,81 +78,31 @@ Starting with yii2-migration v2.0 it is possible to generate updating migration
7878

7979
## Command line parameters
8080

81-
--migrationPath -p
82-
83-
Directory storing the migration classes. _(default '@app/migrations')_
84-
85-
--migrationNamespace -n
86-
87-
Namespace in case of generating namespaced migration. _(default null)_
88-
With this option set `migrationPath` is ignored.
89-
90-
--defaultDecision -d
91-
92-
Default decision what to do in case the file to be generated already exists. _(default 'n')_
93-
Available options are:
94-
95-
- 'y' = asks before every existing file, overwrite is default option,
96-
- 'n' = asks before every existing file, skip is default option,
97-
- 'a' = asks before every existing file, append next number is default option,
98-
- 'o' = doesn't ask, all existing files are overwritten,
99-
- 's' = doesn't ask, no existing files are overwritten,
100-
- 'p' = doesn't ask, all existing files are appended with next number.
101-
102-
Both `create` and `update` action use the same decision mechanism.
103-
104-
--templateFile -F
105-
106-
Template file for generating create migrations. _(default '@vendor/bizley/migration/src/views/create_migration.php')_
107-
108-
--templateFileUpdate -U
109-
110-
[Updates only] Template file for generating update migrations. _(default '@vendor/bizley/migration/src/views/update_migration.php')_
111-
112-
--useTablePrefix -P
113-
114-
Whether the table names generated should consider the `tablePrefix` setting of the DB connection. _(default 1)_
115-
116-
--db
117-
118-
Application component's ID of the DB connection to use when generating migrations. _(default 'db')_
119-
120-
--migrationTable -t
121-
122-
Name of the table for keeping applied migration information. _(default '{{%migration}}')_
123-
The same as in yii\console\controllers\MigrateController::$migrationTable.
124-
125-
--migrationNamespaces -N
126-
127-
[Updates only] List of namespaces containing the migration classes. _(default [])_
128-
The same as in yii\console\controllers\BaseMigrateController::$migrationNamespaces.
129-
130-
--showOnly -s
131-
132-
[Updates only] Whether to only display changes instead of generating update migration. _(default 0)_
133-
134-
--generalSchema -g
135-
136-
Whether to use general column schema instead of database specific. _(default 0)_
81+
| --command | -alias | description | default value
82+
|----------------------|:------:|-------------------------------------------------------------------------|------------------------------------------------------------
83+
| `db` | | Application component's ID of the DB connection to use when generating migrations. | `'db'`
84+
| `migrationPath` | `p` | Directory storing the migration classes. | `'@app/migrations'`
85+
| `migrationNamespace` | `n` | Namespace in case of generating namespaced migration. | `null`
86+
| `templateFile` | `F` | Template file for generating create migrations. | `'@vendor/bizley/migration/src/views/create_migration.php'`
87+
| `templateFileUpdate` | `U` | Template file for generating update migrations. | `'@vendor/bizley/migration/src/views/update_migration.php'`
88+
| `useTablePrefix` | `P` | Whether the table names generated should consider the `tablePrefix` setting of the DB connection. | `1`
89+
| `migrationTable` | `t` | Name of the table for keeping applied migration information. | `'{{%migration}}'`
90+
| `showOnly` | `s` | Whether to only display changes instead of generating update migration. | `0`
91+
| `generalSchema` | `g` | Whether to use general column schema instead of database specific (1). | `0`
92+
| `fixHistory` | `h` | Whether to add migration history entry when migration is generated. | `0`
93+
| `skipMigrations` | | List of migrations from the history table that should be skipped during the update process. (2) | `[]`
94+
95+
(1) Remember that with different database types general column schemas may be generated with different length.
13796

13897
> ### MySQL examples:
13998
> Column `varchar(45)`
14099
> generalSchema=0: `$this->string(45)`
141100
> generalSchema=1: `$this->string()`
142101
> Column `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`
143102
> generalSchema=0: `$this->integer(11)->notNull()->append('AUTO_INCREMENT PRIMARY KEY')`
144-
> generalSchema=1: `$this->primaryKey()`
145-
146-
Remember that with different database types general column schemas may be generated with different length.
147-
148-
--fixHistory -h
149-
150-
Whether to add migration history entry when migration is generated. _(default 0)_
151-
152-
--skipMigrations -k
103+
> generalSchema=1: `$this->primaryKey()`
153104
154-
[Updates only] List of migrations from the history table that should be skipped during the update process. _(default [])_
155-
Here you can place migrations containing actions that can not be covered by extractor i.e. when there is migration
105+
(2) Here you can place migrations containing actions that can not be covered by extractor i.e. when there is migration
156106
setting the RBAC hierarchy with authManager component. Such actions should be kept in separated migration and placed on
157107
this list to prevent them from being run during the extraction process.
158108

src/Updater.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Update migration file generator.
1818
*
1919
* @author Paweł Bizley Brzozowski
20-
* @version 2.1.2
20+
* @version 2.2.0
2121
* @license Apache 2.0
2222
* https://github.com/bizley/yii2-migration
2323
*/
@@ -28,11 +28,6 @@ class Updater extends Generator
2828
*/
2929
public $migrationTable = '{{%migration}}';
3030

31-
/**
32-
* @var array List of namespaces containing the migration classes.
33-
*/
34-
public $migrationNamespaces = [];
35-
3631
/**
3732
* @var string Directory storing the migration classes. This can be either a path alias or a directory.
3833
*/
@@ -96,20 +91,11 @@ public function fetchHistory()
9691
if ($this->db->schema->getTableSchema($this->migrationTable, true) === null) {
9792
return [];
9893
}
99-
$query = (new Query)
94+
$rows = (new Query())
10095
->select(['version', 'apply_time'])
10196
->from($this->migrationTable)
102-
->orderBy(['apply_time' => SORT_DESC, 'version' => SORT_DESC]);
103-
104-
if (empty($this->migrationNamespaces)) {
105-
$rows = $query->all($this->db);
106-
$history = ArrayHelper::map($rows, 'version', 'apply_time');
107-
unset($history[MigrateController::BASE_MIGRATION]);
108-
return $history;
109-
}
110-
111-
$rows = $query->all($this->db);
112-
97+
->orderBy(['apply_time' => SORT_DESC, 'version' => SORT_DESC])
98+
->all($this->db);
11399
$history = [];
114100
foreach ($rows as $key => $row) {
115101
if ($row['version'] === MigrateController::BASE_MIGRATION) {
@@ -132,9 +118,8 @@ public function fetchHistory()
132118
}
133119
return strcasecmp($b['version'], $a['version']);
134120
}
135-
return ($a['apply_time'] > $b['apply_time']) ? 1 : -1;
121+
return ($a['apply_time'] > $b['apply_time']) ? -1 : 1;
136122
});
137-
138123
return ArrayHelper::map($history, 'version', 'apply_time');
139124
}
140125

0 commit comments

Comments
 (0)