Skip to content

Commit 6ac0bf9

Browse files
committed
Merge branch 'master' into 3.2-merge
# Conflicts: # .github/workflows/test.yml # src/command/composer.json # src/serializer/src/Contract/CacheableSupportsMethodInterface.php # src/validation/src/ValidationRuleParser.php
2 parents d120cc7 + a8d2920 commit 6ac0bf9

37 files changed

Lines changed: 1421 additions & 221 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/tests export-ignore
22
/.github export-ignore
3+
/types export-ignore

src/Commands/Migrations/RollbackCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function handle()
4545
[
4646
'pretend' => $this->input->getOption('pretend'),
4747
'step' => (int) $this->input->getOption('step'),
48+
'batch' => (int) $this->input->getOption('batch'),
4849
]
4950
);
5051
}
@@ -63,6 +64,7 @@ protected function getOptions()
6364
['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'],
6465
['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run'],
6566
['step', null, InputOption::VALUE_OPTIONAL, 'The number of migrations to be reverted'],
67+
['batch', null, InputOption::VALUE_OPTIONAL, 'The batch of migrations (identified by their batch number) to be reverted'],
6668
];
6769
}
6870
}

src/Concerns/BuildsQueries.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Hyperf\Database\Exception\RecordsNotFoundException;
2424
use Hyperf\Database\Model\Builder;
2525
use Hyperf\Database\Model\Collection;
26-
use Hyperf\Database\Model\Model;
2726
use Hyperf\Database\Query\Expression;
2827
use Hyperf\Paginator\Contract\CursorPaginator as CursorPaginatorContract;
2928
use Hyperf\Paginator\Cursor;
@@ -36,7 +35,7 @@
3635
use function Hyperf\Collection\data_get;
3736

3837
/**
39-
* @template TValue
38+
* @template TValue of object
4039
* @mixin Builder
4140
* @mixin \Hyperf\Database\Query\Builder
4241
*/
@@ -48,6 +47,7 @@ trait BuildsQueries
4847
* Chunk the results of the query.
4948
*
5049
* @param int $count
50+
* @param callable(BaseCollection<int, TValue>, int): mixed $callback
5151
* @return bool
5252
*/
5353
public function chunk($count, callable $callback)
@@ -85,6 +85,8 @@ public function chunk($count, callable $callback)
8585

8686
/**
8787
* Run a map over each item while chunking.
88+
*
89+
* @param callable(TValue): mixed $callback
8890
*/
8991
public function chunkMap(callable $callback, int $count = 1000): BaseCollection
9092
{
@@ -102,6 +104,7 @@ public function chunkMap(callable $callback, int $count = 1000): BaseCollection
102104
/**
103105
* Execute a callback over each item while chunking.
104106
*
107+
* @param callable(TValue, int): mixed $callback
105108
* @param int $count
106109
* @return bool
107110
*/
@@ -118,6 +121,8 @@ public function each(callable $callback, $count = 1000)
118121

119122
/**
120123
* Query lazily, by chunks of the given size.
124+
*
125+
* @return LazyCollection<int, TValue>
121126
*/
122127
public function lazy(int $chunkSize = 1000): LazyCollection
123128
{
@@ -146,6 +151,8 @@ public function lazy(int $chunkSize = 1000): LazyCollection
146151

147152
/**
148153
* Query lazily, by chunking the results of a query by comparing IDs.
154+
*
155+
* @return LazyCollection<int, TValue>
149156
*/
150157
public function lazyById(int $chunkSize = 1000, ?string $column = null, ?string $alias = null): LazyCollection
151158
{
@@ -154,6 +161,8 @@ public function lazyById(int $chunkSize = 1000, ?string $column = null, ?string
154161

155162
/**
156163
* Query lazily, by chunking the results of a query by comparing IDs in descending order.
164+
*
165+
* @return LazyCollection<int, TValue>
157166
*/
158167
public function lazyByIdDesc(int $chunkSize = 1000, ?string $column = null, ?string $alias = null): LazyCollection
159168
{
@@ -164,7 +173,7 @@ public function lazyByIdDesc(int $chunkSize = 1000, ?string $column = null, ?str
164173
* Execute the query and get the first result.
165174
*
166175
* @param array $columns
167-
* @return null|Model|object|static
176+
* @return null|TValue
168177
*/
169178
public function first($columns = ['*'])
170179
{
@@ -173,6 +182,8 @@ public function first($columns = ['*'])
173182

174183
/**
175184
* Execute a callback over each item while chunking by ID.
185+
*
186+
* @param callable(TValue, int): mixed $callback
176187
*/
177188
public function eachById(callable $callback, int $count = 1000, ?string $column = null, ?string $alias = null): bool
178189
{
@@ -188,6 +199,8 @@ public function eachById(callable $callback, int $count = 1000, ?string $column
188199

189200
/**
190201
* Chunk the results of a query by comparing IDs in a given order.
202+
*
203+
* @param callable(BaseCollection<int, TValue>, int): mixed $callback
191204
*/
192205
public function orderedChunkById(int $count, callable $callback, ?string $column = null, ?string $alias = null, bool $descending = false): bool
193206
{
@@ -240,6 +253,8 @@ public function orderedChunkById(int $count, callable $callback, ?string $column
240253

241254
/**
242255
* Chunk the results of a query by comparing IDs in descending order.
256+
*
257+
* @param callable(BaseCollection<int, TValue>, int): mixed $callback
243258
*/
244259
public function chunkByIdDesc(int $count, callable $callback, ?string $column = null, ?string $alias = null): bool
245260
{

src/Migrations/DatabaseMigrationRepository.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ public function getMigrationBatches()
8888
->pluck('batch', 'migration')->all();
8989
}
9090

91+
/**
92+
* Get the list of the migrations by batch number.
93+
*
94+
* @param int $batch
95+
* @return array
96+
*/
97+
public function getMigrationsByBatch($batch)
98+
{
99+
return $this->table()
100+
->where('batch', $batch)
101+
->orderBy('migration', 'desc')
102+
->get()
103+
->all();
104+
}
105+
91106
/**
92107
* Log that a migration was run.
93108
*

src/Migrations/MigrationRepositoryInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public function getLast();
4343
*/
4444
public function getMigrationBatches();
4545

46+
/**
47+
* Get the list of the migrations by batch number.
48+
*
49+
* @param int $batch
50+
* @return array
51+
*/
52+
public function getMigrationsByBatch($batch);
53+
4654
/**
4755
* Log that a migration was run.
4856
*

src/Migrations/Migrator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ protected function getMigrationsForRollback(array $options): array
355355
return $this->repository->getMigrations($steps);
356356
}
357357

358+
if (($batch = $options['batch'] ?? 0) > 0) {
359+
return $this->repository->getMigrationsByBatch($batch);
360+
}
361+
358362
return $this->repository->getLast();
359363
}
360364

0 commit comments

Comments
 (0)