Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Simplification of the file state system
Browse files Browse the repository at this point in the history
  • Loading branch information
ajthinking committed Dec 15, 2019
1 parent df03506 commit 124c72a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
26 changes: 6 additions & 20 deletions src/Controllers/PipeDreamAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public function build()

// Optionally reverse the previous design iteration
// This is useful to remove previous mistakes and timestamp conflicts
$this->args->reverseHistory ? $this->project->reverseHistory() : null;
// $this->args->reverseHistory ? $this->project->reverseHistory() : null;

// Write the files generated
$this->project->write($this->args->reviewFiles);

// We wont need them
$this->deleteDefaultMigrations();
// If there are user/password_reset tables already present
$this->project->deleteDuplicateDefaultMigrations($this->args->reviewFiles);

// Save the changes we made
$this->project->persistHistory();
// $this->project->persistHistory();

// Ensure migrations are autoloaded
exec('cd .. && composer dumpautoload');
Expand All @@ -50,26 +50,12 @@ public function build()
private function setupProjectEnvironment()
{
$this->project = ProjectFileManager::make(
$this->args->isSandboxed
env('PIPEDREAM_IS_SANDBOXED')
);
}

private function deleteDefaultMigrations()
{
$this->project->delete(json_decode('
[
{
"path": "database/migrations/2014_10_12_000000_create_users_table.php"
},
{
"path": "database/migrations/2014_10_12_100000_create_password_resets_table.php"
}
]
'));
}

private function pathToFileName($path)
{
return substr($path, strrpos($path, '/') + 1);
}
}
}
23 changes: 21 additions & 2 deletions src/ProjectFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function make($isSandboxed)

public function write($files)
{
$this->recordCurrentStateFor($files);
// $this->recordCurrentStateFor($files);

collect($files)->each(function ($file) {
$this->storage()->put($file->path, $file->content);
Expand All @@ -32,7 +32,7 @@ public function write($files)

public function delete($files)
{
$this->recordCurrentStateFor($files);
// $this->recordCurrentStateFor($files);

collect($files)->each(function ($file) {
$this->storage()->delete($file->path);
Expand All @@ -58,6 +58,25 @@ public function persistHistory()
);
}

public function deleteDuplicateDefaultMigrations($files)
{
if(collect($files)->pluck('path')->filter(function($path) {
return preg_match('/create_users_table/', $path);
})->isNotEmpty()) {
$this->delete([
json_decode('{"path": "database/migrations/2014_10_12_000000_create_users_table.php"}')
]);
}

if(collect($files)->pluck('path')->filter(function($path) {
return preg_match('/create_password_resets_table/', $path);
})->isNotEmpty()) {
$this->delete([
json_decode('{"path": "database/migrations/2014_10_12_100000_create_password_resets_table.php"}')
]);
}
}

/*********** PRIVATE ************************************************** */
private function setupSandboxProject()
{
Expand Down

0 comments on commit 124c72a

Please sign in to comment.