From c114a2cad01fbde79a77457f39654ac65c4cadf9 Mon Sep 17 00:00:00 2001 From: inmanturbo Date: Wed, 31 Jul 2024 14:08:21 +0000 Subject: [PATCH 1/3] Update CHANGELOG --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31a2efe..2492a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From e01f58c225819c5bfbb5b565520fc7a85a412da2 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 31 Jul 2024 10:52:21 -0400 Subject: [PATCH 2/3] add libstream:migrate --- config/libstream.php | 6 ++- src/Commands/LibstreamCommand.php | 19 -------- src/Commands/LibstreamMigrateCommand.php | 59 ++++++++++++++++++++++++ src/LibstreamServiceProvider.php | 2 + 4 files changed, 66 insertions(+), 20 deletions(-) delete mode 100644 src/Commands/LibstreamCommand.php create mode 100644 src/Commands/LibstreamMigrateCommand.php diff --git a/config/libstream.php b/config/libstream.php index e8beed4..a569327 100644 --- a/config/libstream.php +++ b/config/libstream.php @@ -2,5 +2,9 @@ // config for Envor/Libstream return [ - + 'migration_tables' => [ + 'stored_events', + 'snapshots', + 'deleted_models', + ], ]; diff --git a/src/Commands/LibstreamCommand.php b/src/Commands/LibstreamCommand.php deleted file mode 100644 index a0b54a0..0000000 --- a/src/Commands/LibstreamCommand.php +++ /dev/null @@ -1,19 +0,0 @@ -comment('All done'); - - return self::SUCCESS; - } -} diff --git a/src/Commands/LibstreamMigrateCommand.php b/src/Commands/LibstreamMigrateCommand.php new file mode 100644 index 0000000..1069dd0 --- /dev/null +++ b/src/Commands/LibstreamMigrateCommand.php @@ -0,0 +1,59 @@ +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); + } + return; + } + + // run the migrations + $options = ['--path' => __DIR__ . '/../../database/migrations']; + if ($this->option('force')) { + $options['--force'] = true; + } + $this->call('migrate', $options, $this->output); + } +} diff --git a/src/LibstreamServiceProvider.php b/src/LibstreamServiceProvider.php index e5f3cf4..2a1fa66 100644 --- a/src/LibstreamServiceProvider.php +++ b/src/LibstreamServiceProvider.php @@ -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', From 8ccf62d7d8f74f5ac3aef8bd2ccdeeab2abe4535 Mon Sep 17 00:00:00 2001 From: inmanturbo Date: Wed, 31 Jul 2024 14:54:22 +0000 Subject: [PATCH 3/3] Fix styling --- src/Commands/LibstreamMigrateCommand.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Commands/LibstreamMigrateCommand.php b/src/Commands/LibstreamMigrateCommand.php index 1069dd0..beb534f 100644 --- a/src/Commands/LibstreamMigrateCommand.php +++ b/src/Commands/LibstreamMigrateCommand.php @@ -14,8 +14,9 @@ class LibstreamMigrateCommand extends Command public function handle(): int { - if($this->option('database')) { - app(DatabaseManager::class)->usingConnection($this->option('database'), fn() => $this->body()); + if ($this->option('database')) { + app(DatabaseManager::class)->usingConnection($this->option('database'), fn () => $this->body()); + return self::SUCCESS; } @@ -32,7 +33,7 @@ private function body() } // delete the migrations from the migrations repository - $files = glob(__DIR__ . '/../../database/migrations/*'); + $files = glob(__DIR__.'/../../database/migrations/*'); foreach ($files as $file) { // get the migration file name without extension @@ -46,11 +47,12 @@ private function body() } $this->call('migrate:reset', $options, $this->output); } + return; } // run the migrations - $options = ['--path' => __DIR__ . '/../../database/migrations']; + $options = ['--path' => __DIR__.'/../../database/migrations']; if ($this->option('force')) { $options['--force'] = true; }