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

Disable check checksum and missing previous executed migrations #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 26 additions & 1 deletion src/Configurations/DefaultConfiguration.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,32 @@ class DefaultConfiguration implements IConfiguration
/** @var ?IDiffGenerator */
protected $dummyDataDiffGenerator;

/** @var bool */
protected $checkChecksum;

/** @var bool */
protected $checkMissingPreviousExecuted;

/**
* @param array<string, mixed> $phpParams
*/
public function __construct(string $dir, IDriver $driver, bool $withDummyData = true, array $phpParams = [])
public function __construct(
string $dir,
IDriver $driver,
bool $withDummyData = true,
array $phpParams = [],
bool $checkChecksum,
bool $checkDependMigration,
bool $checkMissingPreviousExecuted,
)
{
$this->dir = $dir;
$this->driver = $driver;
$this->withDummyData = $withDummyData;
$this->phpParams = $phpParams;
$this->checkChecksum = $checkChecksum;
$this->checkDependMigration = $checkDependMigration;
$this->checkMissingPreviousExecuted = $checkMissingPreviousExecuted;
}


Expand All @@ -66,19 +82,28 @@ public function getGroups(): array
if ($this->groups === null) {
$structures = new Group();
$structures->enabled = true;
$structures->checkChecksum = $this->checkChecksum;
$structures->checkDependMigration = $this->checkDependMigration;
$structures->checkMissingPreviousExecuted = $this->checkMissingPreviousExecuted;
$structures->name = 'structures';
$structures->directory = $this->dir . '/structures';
$structures->dependencies = [];
$structures->generator = $this->structureDiffGenerator;

$basicData = new Group();
$basicData->enabled = true;
$basicData->checkChecksum = $this->checkChecksum;
$basicData->checkDependMigration = $this->checkDependMigration;
$basicData->checkMissingPreviousExecuted = $this->checkMissingPreviousExecuted;
$basicData->name = 'basic-data';
$basicData->directory = $this->dir . '/basic-data';
$basicData->dependencies = ['structures'];

$dummyData = new Group();
$dummyData->enabled = $this->withDummyData;
$dummyData->checkChecksum = $this->checkChecksum;
$basicData->checkDependMigration = $this->checkDependMigration;
$dummyData->checkMissingPreviousExecuted = $this->checkMissingPreviousExecuted;
$dummyData->name = 'dummy-data';
$dummyData->directory = $this->dir . '/dummy-data';
$dummyData->dependencies = ['structures', 'basic-data'];
Expand Down
18 changes: 14 additions & 4 deletions src/Controllers/BaseController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,26 @@ public function __construct(IDriver $driver)
abstract public function run(): void;


/**
* @param list<string> $dependencies
*/
public function addGroup(string $name, string $dir, array $dependencies = []): self
/**
* @param list<string> $dependencies
*/
public function addGroup(
string $name,
string $dir,
array $dependencies = [],
bool $checkChecksum = true,
bool $checkMissingPreviousExecuted = true,
bool $checkDependMigration = true,
): self
{
$group = new Group;
$group->name = $name;
$group->directory = $dir;
$group->dependencies = $dependencies;
$group->enabled = false;
$group->checkChecksum = $checkChecksum;
$group->checkMissingPreviousExecuted = $checkMissingPreviousExecuted;
$group->checkDependMigration = $checkDependMigration;

$this->groups[$name] = $group;
return $this;
Expand Down
9 changes: 7 additions & 2 deletions src/Engine/OrderResolver.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class OrderResolver
{

/**
* @param list<Migration> $migrations
* @param list<Group> $groups
Expand Down Expand Up @@ -58,15 +59,15 @@ public function resolve(array $migrations, array $groups, array $files, string $

if (isset($files[$groupName][$filename])) {
$file = $files[$groupName][$filename];
if ($migration->checksum !== $file->checksum) {
if ($group->checkChecksum && $migration->checksum !== $file->checksum) {
throw new LogicException(sprintf(
'Previously executed migration "%s/%s" has been changed. File checksum is "%s", but executed migration had checksum "%s".',
$groupName, $filename, $file->checksum, $migration->checksum
));
}
unset($files[$groupName][$filename]);

} elseif ($group->enabled) {
} elseif ($group->checkMissingPreviousExecuted && $group->enabled) {
throw new LogicException(sprintf(
'Previously executed migration "%s/%s" is missing.',
$groupName, $filename
Expand All @@ -87,6 +88,10 @@ public function resolve(array $migrations, array $groups, array $files, string $
continue;
}

if (!$group->checkDependMigration) {
continue;
}

foreach ($this->getFirstFiles($files) as $file) {
if (strcmp($file->name, $lastMigrations[$group->name]) >= 0) {
continue;
Expand Down
9 changes: 9 additions & 0 deletions src/Entities/Group.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class Group
/** @var bool */
public $enabled;

/** @var bool */
public $checkChecksum = true;

/** @var bool */
public $checkDependMigration = true;

/** @var bool */
public $checkMissingPreviousExecuted = true;

/** @var string absolute path do directory */
public $directory;

Expand Down