Skip to content
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
17 changes: 16 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,22 @@ protected function getMigrationChecksumFile(): string
return storage_path('custom/some-other-file.txt');
}
```


## Customising the migration path locations

You may customise the migration path locations by extending the trait and overwriting the `getCustomMigrationPaths()` method.

```php
protected function getCustomMigrationPaths(): array
{
return [
database_path('other-migrations'),
];
}
```

If you require full control over the migration paths, you may overwrite the `getMigrationPaths()` method.

## Known Issues

### ParaTest Databases
Expand Down
48 changes: 37 additions & 11 deletions src/Traits/FastRefreshDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait FastRefreshDatabase
* @return void
* @throws \JsonException
*/
protected function refreshTestDatabase()
protected function refreshTestDatabase(): void
{
if (! RefreshDatabaseState::$migrated) {
$cachedChecksum = FastRefreshDatabaseState::$cachedChecksum ??= $this->getCachedMigrationChecksum();
Expand Down Expand Up @@ -48,30 +48,32 @@ protected function refreshTestDatabase()
*/
protected function calculateMigrationChecksum(): string
{
// Filter out non-existing paths
$paths = collect($this->getMigrationPaths())
->map(fn ($path) => realpath($path))
->toArray();

$finder = Finder::create()
->in(database_path('migrations'))
->in($paths)
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
->files();

$migrations = array_map(static function (SplFileInfo $fileInfo) {
return [$fileInfo->getMTime(), $fileInfo->getPath()];
}, iterator_to_array($finder));

// Reset the array keys so there is less data

$migrations = array_values($migrations);
// Get all the migration files and their last modified date
$migrations = collect(iterator_to_array($finder))
->map(fn (SplFileInfo $fileInfo) => [$fileInfo->getMTime()])
// Reset the array keys so there is less data
->values()
->toArray();

// Add the current git branch

$checkBranch = new Process(['git', 'branch', '--show-current']);
$checkBranch->run();

$migrations['gitBranch'] = trim($checkBranch->getOutput());

// Create a hash

return hash('sha256', json_encode($migrations, JSON_THROW_ON_ERROR));
}

Expand All @@ -96,6 +98,30 @@ protected function storeMigrationChecksum(string $checksum): void
file_put_contents($this->getMigrationChecksumFile(), $checksum);
}

/**
* The paths that should be used to discover migrations
*
* @return array<string>
*/
protected function getMigrationPaths(): array
{
return [
database_path('migrations'),
...app('migrator')->paths(),
...$this->getCustomMigrationPaths(),
];
}

/**
* Custom migration paths that should be used when discovering migrations
*
* @return array<string>
*/
protected function getCustomMigrationPaths(): array
{
return [];
}

/**
* Provides a configurable migration checksum file path
*
Expand Down