Skip to content

Commit bf91999

Browse files
add checkChecksum and checkMissingPreviousExecuted to group
1 parent c1a201d commit bf91999

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

src/Configurations/DefaultConfiguration.php

100644100755
+26-1
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,32 @@ class DefaultConfiguration implements IConfiguration
4848
/** @var ?IDiffGenerator */
4949
protected $dummyDataDiffGenerator;
5050

51+
/** @var bool */
52+
protected $checkChecksum;
53+
54+
/** @var bool */
55+
protected $checkMissingPreviousExecuted;
5156

5257
/**
5358
* @param array<string, mixed> $phpParams
5459
*/
55-
public function __construct(string $dir, IDriver $driver, bool $withDummyData = true, array $phpParams = [])
60+
public function __construct(
61+
string $dir,
62+
IDriver $driver,
63+
bool $withDummyData = true,
64+
array $phpParams = [],
65+
bool $checkChecksum,
66+
bool $checkDependMigration,
67+
bool $checkMissingPreviousExecuted,
68+
)
5669
{
5770
$this->dir = $dir;
5871
$this->driver = $driver;
5972
$this->withDummyData = $withDummyData;
6073
$this->phpParams = $phpParams;
74+
$this->checkChecksum = $checkChecksum;
75+
$this->checkDependMigration = $checkDependMigration;
76+
$this->checkMissingPreviousExecuted = $checkMissingPreviousExecuted;
6177
}
6278

6379

@@ -66,19 +82,28 @@ public function getGroups(): array
6682
if ($this->groups === null) {
6783
$structures = new Group();
6884
$structures->enabled = true;
85+
$structures->checkChecksum = $this->checkChecksum;
86+
$structures->checkDependMigration = $this->checkDependMigration;
87+
$structures->checkMissingPreviousExecuted = $this->checkMissingPreviousExecuted;
6988
$structures->name = 'structures';
7089
$structures->directory = $this->dir . '/structures';
7190
$structures->dependencies = [];
7291
$structures->generator = $this->structureDiffGenerator;
7392

7493
$basicData = new Group();
7594
$basicData->enabled = true;
95+
$basicData->checkChecksum = $this->checkChecksum;
96+
$basicData->checkDependMigration = $this->checkDependMigration;
97+
$basicData->checkMissingPreviousExecuted = $this->checkMissingPreviousExecuted;
7698
$basicData->name = 'basic-data';
7799
$basicData->directory = $this->dir . '/basic-data';
78100
$basicData->dependencies = ['structures'];
79101

80102
$dummyData = new Group();
81103
$dummyData->enabled = $this->withDummyData;
104+
$dummyData->checkChecksum = $this->checkChecksum;
105+
$basicData->checkDependMigration = $this->checkDependMigration;
106+
$dummyData->checkMissingPreviousExecuted = $this->checkMissingPreviousExecuted;
82107
$dummyData->name = 'dummy-data';
83108
$dummyData->directory = $this->dir . '/dummy-data';
84109
$dummyData->dependencies = ['structures', 'basic-data'];

src/Controllers/BaseController.php

100644100755
+14-4
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,26 @@ public function __construct(IDriver $driver)
4040
abstract public function run(): void;
4141

4242

43-
/**
44-
* @param list<string> $dependencies
45-
*/
46-
public function addGroup(string $name, string $dir, array $dependencies = []): self
43+
/**
44+
* @param list<string> $dependencies
45+
*/
46+
public function addGroup(
47+
string $name,
48+
string $dir,
49+
array $dependencies = [],
50+
bool $checkChecksum = true,
51+
bool $checkMissingPreviousExecuted = true,
52+
bool $checkDependMigration = true,
53+
): self
4754
{
4855
$group = new Group;
4956
$group->name = $name;
5057
$group->directory = $dir;
5158
$group->dependencies = $dependencies;
5259
$group->enabled = false;
60+
$group->checkChecksum = $checkChecksum;
61+
$group->checkMissingPreviousExecuted = $checkMissingPreviousExecuted;
62+
$group->checkDependMigration = $checkDependMigration;
5363

5464
$this->groups[$name] = $group;
5565
return $this;

src/Engine/OrderResolver.php

100644100755
+6-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
class OrderResolver
1919
{
20+
2021
/**
2122
* @param list<Migration> $migrations
2223
* @param list<Group> $groups
@@ -58,15 +59,15 @@ public function resolve(array $migrations, array $groups, array $files, string $
5859

5960
if (isset($files[$groupName][$filename])) {
6061
$file = $files[$groupName][$filename];
61-
if ($migration->checksum !== $file->checksum) {
62+
if ($group->checkChecksum && $migration->checksum !== $file->checksum) {
6263
throw new LogicException(sprintf(
6364
'Previously executed migration "%s/%s" has been changed. File checksum is "%s", but executed migration had checksum "%s".',
6465
$groupName, $filename, $file->checksum, $migration->checksum
6566
));
6667
}
6768
unset($files[$groupName][$filename]);
6869

69-
} elseif ($group->enabled) {
70+
} elseif ($group->checkMissingPreviousExecuted && $group->enabled) {
7071
throw new LogicException(sprintf(
7172
'Previously executed migration "%s/%s" is missing.',
7273
$groupName, $filename
@@ -92,7 +93,9 @@ public function resolve(array $migrations, array $groups, array $files, string $
9293
continue;
9394
}
9495

95-
if ($this->isGroupDependentOn($groups, $file->group, $group) || $this->isGroupDependentOn($groups, $group, $file->group)) {
96+
if ($group->checkDependMigration && $this->isGroupDependentOn($groups, $file->group, $group)
97+
|| $this->isGroupDependentOn($groups, $group, $file->group)
98+
) {
9699
throw new LogicException(sprintf(
97100
'New migration "%s/%s" must follow after the latest executed migration "%s/%s".',
98101
$file->group->name, $file->name, $group->name, $lastMigrations[$group->name]

src/Entities/Group.php

100644100755
+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ class Group
2323
/** @var bool */
2424
public $enabled;
2525

26+
/** @var bool */
27+
public $checkChecksum = true;
28+
29+
/** @var bool */
30+
public $checkDependMigration = true;
31+
32+
/** @var bool */
33+
public $checkMissingPreviousExecuted = true;
34+
2635
/** @var string absolute path do directory */
2736
public $directory;
2837

0 commit comments

Comments
 (0)