Skip to content

Commit 1ff3e6e

Browse files
authored
Merge pull request #7894 from kenjis/fix-migration-db-group
fix: `spark migrate` `-g` option
2 parents 64819ee + a58258f commit 1ff3e6e

File tree

5 files changed

+30
-32
lines changed

5 files changed

+30
-32
lines changed

app/Config/Migrations.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ class Migrations extends BaseConfig
2525
*
2626
* This is the name of the table that will store the current migrations state.
2727
* When migrations runs it will store in a database table which migration
28-
* level the system is at. It then compares the migration level in this
29-
* table to the $config['migration_version'] if they are not the same it
30-
* will migrate up. This must be set.
28+
* files have already been run.
3129
*/
3230
public string $table = 'migrations';
3331

system/Commands/Database/MigrateRollback.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class MigrateRollback extends BaseCommand
5858
*/
5959
protected $options = [
6060
'-b' => 'Specify a batch to roll back to; e.g. "3" to return to batch #3',
61-
'-g' => 'Set database group',
6261
'-f' => 'Force command - this option allows you to bypass the confirmation question when running this command in a production environment',
6362
];
6463

@@ -79,11 +78,6 @@ public function run(array $params)
7978
}
8079

8180
$runner = Services::migrations();
82-
$group = $params['g'] ?? CLI::getOption('g');
83-
84-
if (is_string($group)) {
85-
$runner->setGroup($group);
86-
}
8781

8882
try {
8983
$batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;

system/Database/MigrationRunner.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ public function latest(?string $group = null)
220220
*
221221
* Calls each migration step required to get to the provided batch
222222
*
223-
* @param int $targetBatch Target batch number, or negative for a relative batch, 0 for all
223+
* @param int $targetBatch Target batch number, or negative for a relative batch, 0 for all
224+
* @param string|null $group Deprecated. The designation has no effect.
224225
*
225-
* @return mixed Current batch number on success, FALSE on failure or no migrations are found
226+
* @return bool True on success, FALSE on failure or no migrations are found
226227
*
227228
* @throws ConfigException
228229
* @throws RuntimeException
@@ -233,11 +234,6 @@ public function regress(int $targetBatch = 0, ?string $group = null)
233234
throw ConfigException::forDisabledMigrations();
234235
}
235236

236-
// Set database group if not null
237-
if ($group !== null) {
238-
$this->setGroup($group);
239-
}
240-
241237
$this->ensureTable();
242238

243239
$batches = $this->getBatches();

user_guide_src/source/changelogs/v4.4.2.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Message Changes
1818
Changes
1919
*******
2020

21+
- **Database Migrations:** The ``-g`` option for the ``spark migrate:rollback``
22+
command was removed. It did not work from the beginning. Also, the rollback
23+
command returns the database(s) state to a specified batch number and cannot
24+
specify only a specific database group.
25+
2126
Deprecations
2227
************
2328

user_guide_src/source/dbmgmt/migration.rst

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ Database Groups
6767

6868
A migration will only be run against a single database group. If you have multiple groups defined in
6969
**app/Config/Database.php**, then it will run against the ``$defaultGroup`` as specified
70-
in that same configuration file. There may be times when you need different schemas for different
70+
in that same configuration file.
71+
72+
There may be times when you need different schemas for different
7173
database groups. Perhaps you have one database that is used for all general site information, while
72-
another database is used for mission critical data. You can ensure that migrations are run only
74+
another database is used for mission critical data.
75+
76+
You can ensure that migrations are run only
7377
against the proper group by setting the ``$DBGroup`` property on your migration. This name must
7478
match the name of the database group exactly:
7579

@@ -115,8 +119,8 @@ Migrates a database group with all available migrations:
115119
116120
You can use (migrate) with the following options:
117121

118-
- ``-g`` - to chose database group, otherwise default database group will be used.
119-
- ``-n`` - to choose namespace, otherwise (App) namespace will be used.
122+
- ``-g`` - to specify database group. If specified, only migrations for the specified database group will be run. If not specified, all migrations will be run.
123+
- ``-n`` - to choose namespace, otherwise ``App`` namespace will be used.
120124
- ``--all`` - to migrate all namespaces to the latest migration.
121125

122126
This example will migrate ``Acme\Blog`` namespace with any new migrations on the test database group:
@@ -140,15 +144,14 @@ to minimize any potential conflicts between the main application and any modules
140144
rollback
141145
========
142146

143-
Rolls back all migrations, taking the database group to a blank slate, effectively migration 0:
147+
Rolls back all migrations to a blank slate, effectively migration 0:
144148

145149
.. code-block:: console
146150
147151
php spark migrate:rollback
148152
149153
You can use (rollback) with the following options:
150154

151-
- ``-g`` - to choose database group, otherwise default database group will be used.
152155
- ``-b`` - to choose a batch: natural numbers specify the batch.
153156
- ``-f`` - to force a bypass confirmation question, it is only asked in a production environment.
154157

@@ -163,8 +166,8 @@ Refreshes the database state by first rolling back all migrations, and then migr
163166
164167
You can use (refresh) with the following options:
165168

166-
- ``-g`` - to choose database group, otherwise default database group will be used.
167-
- ``-n`` - to choose namespace, otherwise (App) namespace will be used.
169+
- ``-g`` - to specify database group. If specified, only migrations for the specified database group will be run. If not specified, all migrations will be run.
170+
- ``-n`` - to choose namespace, otherwise ``App`` namespace will be used.
168171
- ``--all`` - to refresh all namespaces.
169172
- ``-f`` - to force a bypass confirmation question, it is only asked in a production environment.
170173

@@ -189,7 +192,7 @@ Displays a list of all migrations and the date and time they ran, or '--' if the
189192
190193
You can use (status) with the following options:
191194

192-
- ``-g`` - to choose database group, otherwise default database group will be used.
195+
- ``-g`` - to specify database group. If specified, only migrations for the specified database group will be checked. If not specified, all migrations will be checked.
193196

194197
make:migration
195198
==============
@@ -220,13 +223,15 @@ Migration Preferences
220223

221224
The following is a table of all the config options for migrations, available in **app/Config/Migrations.php**.
222225

223-
========================== ====================== ========================== =============================================================
224-
Preference Default Options Description
225-
========================== ====================== ========================== =============================================================
226-
**enabled** true true / false Enable or disable migrations.
227-
**table** migrations None The table name for storing the schema version number.
228-
**timestampFormat** Y-m-d-His\_ The format to use for timestamps when creating a migration.
229-
========================== ====================== ========================== =============================================================
226+
==================== ============ ============= =============================================================
227+
Preference Default Options Description
228+
==================== ============ ============= =============================================================
229+
**enabled** true true / false Enable or disable migrations.
230+
**table** migrations None The table name for storing the schema version number. This
231+
table is always created in the default database group
232+
(``$defaultGroup``).
233+
**timestampFormat** Y-m-d-His\_ The format to use for timestamps when creating a migration.
234+
==================== ============ ============= =============================================================
230235

231236
***************
232237
Class Reference

0 commit comments

Comments
 (0)