From 1b8c772a33063603096c7edb5d549b58a6798a76 Mon Sep 17 00:00:00 2001 From: Muhammet SAFAK Date: Sun, 10 Jul 2022 08:22:46 +0300 Subject: [PATCH] The create command has been added to the console application to create a new migration file. --- README.md | 20 +++++++++++++------- barbarian | 29 ++++++++++++++++++++++++++++- src/MigrationAbstract.php | 2 +- src/MigrationException.php | 2 +- src/MigrationInterface.php | 2 +- src/Migrations.php | 8 ++++++-- src/QueryInterface.php | 2 +- 7 files changed, 51 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 57df64f..4f7b42a 100644 --- a/README.md +++ b/README.md @@ -94,44 +94,50 @@ To use the CLI interface, first create the "`barbarian.json`" file in your worki Or you can try to create this file with the command below. ``` -php barbarian json +vendor/bin/barbarian json +``` + +You can use the command below to create a new migration class. + +``` +vendor/bin/barbarian create ``` You can use the command below to up all migrations. ``` -php barbarian up +vendor/bin/barbarian up ``` You can use the `-version` flag to only up a migration. ``` -php barbarian up -version=20221230153013 +vendor/bin/barbarian up -version=20221230153013 ``` or ``` -php barbarian up -version=Migration_20221230153013 +vendor/bin/barbarian up -version=Migration_20221230153013 ``` You can use the command below to down all migrations. ``` -php barbarian down +vendor/bin/barbarian down ``` You can use the `-version` flag to only up a migration. ``` -php barbarian down -version=20221230153013 +vendor/bin/barbarian down -version=20221230153013 ``` or ``` -php barbarian down -version=Migration_20221230153013 +vendor/bin/barbarian down -version=Migration_20221230153013 ``` ## Credits diff --git a/barbarian b/barbarian index 880fb2b..f8fe3d0 100644 --- a/barbarian +++ b/barbarian @@ -180,5 +180,32 @@ $console->register('down', function (Console $console) { } }, 'Runs the down() method of the Migration class.'); +$console->register('create', function (Console $console) { + $migration = barbarian_json_migration_start(); + $dir = $migration->getOption('folder'); + $namespace = $migration->getOption('namespace'); + $name = 'Migration_' . date("YmdHis"); + + $content = 'warning('"' . $name . '" already exists.'); + exit; + } + + if((@file_put_contents($path, $content)) === FALSE){ + $console->warning('Failed to create "' . $name . '".'); + exit; + } + $console->success('"'.$name.'" migration created.'); +}, 'Creates a new Migration class.'); + -$console->run(); \ No newline at end of file +$console->run(); diff --git a/src/MigrationAbstract.php b/src/MigrationAbstract.php index d52cc9b..dcc8f0a 100644 --- a/src/MigrationAbstract.php +++ b/src/MigrationAbstract.php @@ -7,7 +7,7 @@ * @author Muhammet ŞAFAK * @copyright Copyright © 2022 Muhammet ŞAFAK * @license ./LICENSE MIT - * @version 1.0 + * @version 1.0.1 * @link https://www.muhammetsafak.com.tr */ diff --git a/src/MigrationException.php b/src/MigrationException.php index 53540e8..8e44890 100644 --- a/src/MigrationException.php +++ b/src/MigrationException.php @@ -7,7 +7,7 @@ * @author Muhammet ŞAFAK * @copyright Copyright © 2022 Muhammet ŞAFAK * @license ./LICENSE MIT - * @version 1.0 + * @version 1.0.1 * @link https://www.muhammetsafak.com.tr */ diff --git a/src/MigrationInterface.php b/src/MigrationInterface.php index 1ed0842..d96833d 100644 --- a/src/MigrationInterface.php +++ b/src/MigrationInterface.php @@ -7,7 +7,7 @@ * @author Muhammet ŞAFAK * @copyright Copyright © 2022 Muhammet ŞAFAK * @license ./LICENSE MIT - * @version 1.0 + * @version 1.0.1 * @link https://www.muhammetsafak.com.tr */ diff --git a/src/Migrations.php b/src/Migrations.php index 6451461..caaba57 100644 --- a/src/Migrations.php +++ b/src/Migrations.php @@ -7,7 +7,7 @@ * @author Muhammet ŞAFAK * @copyright Copyright © 2022 Muhammet ŞAFAK * @license ./LICENSE MIT - * @version 1.0 + * @version 1.0.1 * @link https://www.muhammetsafak.com.tr */ @@ -127,6 +127,11 @@ public function downMigration(MigrationInterface $migration): bool return false; } + public function getOption(string $key, $default = null) + { + return $this->options[$key] ?? $default; + } + protected function setMigrationTable(string $table): self { if(((bool)preg_match('/^[a-zA-Z_]+$/', $table)) === FALSE){ @@ -176,7 +181,6 @@ protected function folder_scan() } } - private function migration_versions_table_exists() { switch ($this->driver) { diff --git a/src/QueryInterface.php b/src/QueryInterface.php index fee58e9..cf21e56 100644 --- a/src/QueryInterface.php +++ b/src/QueryInterface.php @@ -7,7 +7,7 @@ * @author Muhammet ŞAFAK * @copyright Copyright © 2022 Muhammet ŞAFAK * @license ./LICENSE MIT - * @version 1.0 + * @version 1.0.1 * @link https://www.muhammetsafak.com.tr */