Skip to content

Commit

Permalink
Merge pull request #2 from envor/main
Browse files Browse the repository at this point in the history
Libstream Migrate
  • Loading branch information
inmanturbo authored Jul 31, 2024
2 parents 8b08ded + 8ccf62d commit acd84d0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 20 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to `libstream` will be documented in this file.

## v1.0.1 - 2024-07-31

### What's Changed

* Main by @inmanturbo in https://github.com/envor/envor-libstream/pull/1

### New Contributors

* @inmanturbo made their first contribution in https://github.com/envor/envor-libstream/pull/1

**Full Changelog**: https://github.com/envor/envor-libstream/compare/v1.0.0...v1.0.1

## v1.0.0 - 2024-07-31

**Full Changelog**: https://github.com/envor/envor-libstream/commits/v1.0.0
6 changes: 5 additions & 1 deletion config/libstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

// config for Envor/Libstream
return [

'migration_tables' => [
'stored_events',
'snapshots',
'deleted_models',
],
];
19 changes: 0 additions & 19 deletions src/Commands/LibstreamCommand.php

This file was deleted.

61 changes: 61 additions & 0 deletions src/Commands/LibstreamMigrateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Envor\Libstream\Commands;

use Illuminate\Console\Command;
use Illuminate\Database\DatabaseManager;
use Illuminate\Support\Facades\Schema;

class LibstreamMigrateCommand extends Command
{
public $signature = 'libstream:migrate {--force : Run the command without asking for confirmation} {--fresh : Drop all libstream tables and re-run migrations} {--database= : The database connection to use}';

public $description = 'Run the libstream migrations';

public function handle(): int
{
if ($this->option('database')) {
app(DatabaseManager::class)->usingConnection($this->option('database'), fn () => $this->body());

return self::SUCCESS;
}

$this->body();

return self::SUCCESS;
}

private function body()
{
if ($this->option('fresh')) {
foreach (config('libstream.migration_tables') as $table) {
Schema::dropIfExists($table);
}

// delete the migrations from the migrations repository
$files = glob(__DIR__.'/../../database/migrations/*');

foreach ($files as $file) {
// get the migration file name without extension
$fileName = pathinfo($file, PATHINFO_FILENAME);
//get full realpath to file
$realpath = realpath($file);
// delete the migration from the migrations repository
$options = ['--path' => $realpath, '--realpath' => true];
if ($this->option('force')) {
$options['--force'] = true;
}
$this->call('migrate:reset', $options, $this->output);

Check failure on line 48 in src/Commands/LibstreamMigrateCommand.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Illuminate\Console\Command::call() invoked with 3 parameters, 1-2 required.

Check failure on line 48 in src/Commands/LibstreamMigrateCommand.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Illuminate\Console\Command::call() invoked with 3 parameters, 1-2 required.
}

return;
}

// run the migrations
$options = ['--path' => __DIR__.'/../../database/migrations'];
if ($this->option('force')) {
$options['--force'] = true;
}
$this->call('migrate', $options, $this->output);

Check failure on line 59 in src/Commands/LibstreamMigrateCommand.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Illuminate\Console\Command::call() invoked with 3 parameters, 1-2 required.

Check failure on line 59 in src/Commands/LibstreamMigrateCommand.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Illuminate\Console\Command::call() invoked with 3 parameters, 1-2 required.
}
}
2 changes: 2 additions & 0 deletions src/LibstreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function configurePackage(Package $package): void
*/
$package
->name('libstream')
->hasConfigFile()
->hasCommand(Commands\LibstreamMigrateCommand::class)
->hasMigrations([
'2024_06_26_194318_create_stored_events_table',
'2024_06_26_194319_create_snapshots_table',
Expand Down

0 comments on commit acd84d0

Please sign in to comment.