From 73a64ff717a3bd2421cfe5c3382adb272519653c Mon Sep 17 00:00:00 2001 From: Kavalar Date: Fri, 13 Dec 2024 14:27:46 +0300 Subject: [PATCH] migration rollback at path, additional info routs --- composer.lock | 132 +++++++++--------- kernel/CgRouteCollector.php | 12 +- kernel/app_modules/tag/TagModule.php | 9 +- .../2024_10_08_093710_create_tag_table.php | 2 + ...4_11_25_122506_create_tag_entity_table.php | 2 + kernel/console/Out.php | 5 + kernel/console/controllers/MainController.php | 21 ++- .../console/migrations/stubs/migration.stub | 1 + kernel/console/routs/cli.php | 18 ++- kernel/controllers/ModuleController.php | 1 + kernel/modules/post/PostModule.php | 6 + .../2024_09_23_130017_create_post_table.php | 2 + kernel/services/MigrationService.php | 21 +++ 13 files changed, 156 insertions(+), 76 deletions(-) rename kernel/app_modules/tag/migrations/{tag => }/2024_10_08_093710_create_tag_table.php (96%) rename kernel/app_modules/tag/migrations/{tag_entity => }/2024_11_25_122506_create_tag_entity_table.php (96%) diff --git a/composer.lock b/composer.lock index 7bd734c..15f00bd 100644 --- a/composer.lock +++ b/composer.lock @@ -137,16 +137,16 @@ }, { "name": "craft-group/phroute", - "version": "v2.1.2", + "version": "v2.1.3", "source": { "type": "git", "url": "https://github.com/apuc/phroute.git", - "reference": "49180faae85e0ba3b0165901ad46e08508c81fac" + "reference": "cc04353cd0fb1cc4ff73f273a5718023a767f150" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/apuc/phroute/zipball/49180faae85e0ba3b0165901ad46e08508c81fac", - "reference": "49180faae85e0ba3b0165901ad46e08508c81fac", + "url": "https://api.github.com/repos/apuc/phroute/zipball/cc04353cd0fb1cc4ff73f273a5718023a767f150", + "reference": "cc04353cd0fb1cc4ff73f273a5718023a767f150", "shasum": "" }, "require": { @@ -178,9 +178,9 @@ "routing" ], "support": { - "source": "https://github.com/apuc/phroute/tree/v2.1.2" + "source": "https://github.com/apuc/phroute/tree/v2.1.3" }, - "time": "2022-12-17T18:27:33+00:00" + "time": "2024-12-13T09:08:04+00:00" }, { "name": "doctrine/inflector", @@ -725,16 +725,16 @@ }, { "name": "illuminate/collections", - "version": "v11.34.2", + "version": "v11.35.1", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "fd2103ddc121449a7926fc34a9d220e5b88183c1" + "reference": "b8be9c0fedfc5be1524b290fed640d4b7d42c813" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/fd2103ddc121449a7926fc34a9d220e5b88183c1", - "reference": "fd2103ddc121449a7926fc34a9d220e5b88183c1", + "url": "https://api.github.com/repos/illuminate/collections/zipball/b8be9c0fedfc5be1524b290fed640d4b7d42c813", + "reference": "b8be9c0fedfc5be1524b290fed640d4b7d42c813", "shasum": "" }, "require": { @@ -754,6 +754,7 @@ }, "autoload": { "files": [ + "functions.php", "helpers.php" ], "psr-4": { @@ -776,11 +777,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-11-27T14:51:56+00:00" + "time": "2024-12-10T14:54:28+00:00" }, { "name": "illuminate/conditionable", - "version": "v11.34.2", + "version": "v11.35.1", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -826,16 +827,16 @@ }, { "name": "illuminate/container", - "version": "v11.34.2", + "version": "v11.35.1", "source": { "type": "git", "url": "https://github.com/illuminate/container.git", - "reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26" + "reference": "4a777578ce2388384565bf5c8e76881f0da68e54" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/container/zipball/b057b0bbb38d7c7524df1ca5c38e7318f4c64d26", - "reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26", + "url": "https://api.github.com/repos/illuminate/container/zipball/4a777578ce2388384565bf5c8e76881f0da68e54", + "reference": "4a777578ce2388384565bf5c8e76881f0da68e54", "shasum": "" }, "require": { @@ -873,11 +874,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-11-21T20:07:31+00:00" + "time": "2024-12-08T15:40:56+00:00" }, { "name": "illuminate/contracts", - "version": "v11.34.2", + "version": "v11.35.1", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", @@ -1060,7 +1061,7 @@ }, { "name": "illuminate/macroable", - "version": "v11.34.2", + "version": "v11.35.1", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -1106,16 +1107,16 @@ }, { "name": "illuminate/support", - "version": "v11.34.2", + "version": "v11.35.1", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "2b718a86571baed50fdc5d5748a846c2e58e07eb" + "reference": "bc363403d9ed3214754a0501e33c05d2afcfd474" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/2b718a86571baed50fdc5d5748a846c2e58e07eb", - "reference": "2b718a86571baed50fdc5d5748a846c2e58e07eb", + "url": "https://api.github.com/repos/illuminate/support/zipball/bc363403d9ed3214754a0501e33c05d2afcfd474", + "reference": "bc363403d9ed3214754a0501e33c05d2afcfd474", "shasum": "" }, "require": { @@ -1138,11 +1139,12 @@ "spatie/once": "*" }, "suggest": { - "illuminate/filesystem": "Required to use the composer class (^11.0).", + "illuminate/filesystem": "Required to use the Composer class (^11.0).", "laravel/serializable-closure": "Required to use the once function (^1.3).", "league/commonmark": "Required to use Str::markdown() and Stringable::markdown() (^2.0.2).", + "league/uri": "Required to use the Uri class (^7.5.1).", "ramsey/uuid": "Required to use Str::uuid() (^4.7).", - "symfony/process": "Required to use the composer class (^7.0).", + "symfony/process": "Required to use the Composer class (^7.0).", "symfony/uid": "Required to use Str::ulid() (^7.0).", "symfony/var-dumper": "Required to use the dd function (^7.0).", "vlucas/phpdotenv": "Required to use the Env class and env helper (^5.6.1)." @@ -1178,7 +1180,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-11-27T14:58:17+00:00" + "time": "2024-12-11T23:23:18+00:00" }, { "name": "itguild/eloquent-table", @@ -1217,11 +1219,11 @@ }, { "name": "itguild/forms", - "version": "0.1.5", + "version": "0.1.6", "source": { "type": "git", "url": "https://git.itguild.info/ItGuild/forms_bundle.git", - "reference": "45e57367d3f9571fde2b82fa2fd8126469ba6db6" + "reference": "53e5fadfc1e250a397486565d30f27f3853e0559" }, "require": { "itguild/php-cg-select-v2": "^0.1.0", @@ -1245,7 +1247,7 @@ "email": "apuc06@mail.ru" } ], - "time": "2024-11-28T10:18:58+00:00" + "time": "2024-12-09T20:06:48+00:00" }, { "name": "itguild/php-cg-select-v2", @@ -2220,16 +2222,16 @@ }, { "name": "symfony/clock", - "version": "v7.1.6", + "version": "v7.2.0", "source": { "type": "git", "url": "https://github.com/symfony/clock.git", - "reference": "97bebc53548684c17ed696bc8af016880f0f098d" + "reference": "b81435fbd6648ea425d1ee96a2d8e68f4ceacd24" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/clock/zipball/97bebc53548684c17ed696bc8af016880f0f098d", - "reference": "97bebc53548684c17ed696bc8af016880f0f098d", + "url": "https://api.github.com/repos/symfony/clock/zipball/b81435fbd6648ea425d1ee96a2d8e68f4ceacd24", + "reference": "b81435fbd6648ea425d1ee96a2d8e68f4ceacd24", "shasum": "" }, "require": { @@ -2274,7 +2276,7 @@ "time" ], "support": { - "source": "https://github.com/symfony/clock/tree/v7.1.6" + "source": "https://github.com/symfony/clock/tree/v7.2.0" }, "funding": [ { @@ -2290,7 +2292,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/deprecation-contracts", @@ -2361,16 +2363,16 @@ }, { "name": "symfony/finder", - "version": "v7.1.6", + "version": "v7.2.0", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8" + "reference": "6de263e5868b9a137602dd1e33e4d48bfae99c49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/2cb89664897be33f78c65d3d2845954c8d7a43b8", - "reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8", + "url": "https://api.github.com/repos/symfony/finder/zipball/6de263e5868b9a137602dd1e33e4d48bfae99c49", + "reference": "6de263e5868b9a137602dd1e33e4d48bfae99c49", "shasum": "" }, "require": { @@ -2405,7 +2407,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.6" + "source": "https://github.com/symfony/finder/tree/v7.2.0" }, "funding": [ { @@ -2421,7 +2423,7 @@ "type": "tidelift" } ], - "time": "2024-10-01T08:31:23+00:00" + "time": "2024-10-23T06:56:12+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2449,8 +2451,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -2528,8 +2530,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -2602,8 +2604,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -2682,8 +2684,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -2758,8 +2760,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -2816,20 +2818,21 @@ }, { "name": "symfony/translation", - "version": "v7.1.6", + "version": "v7.2.0", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "b9f72ab14efdb6b772f85041fa12f820dee8d55f" + "reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/b9f72ab14efdb6b772f85041fa12f820dee8d55f", - "reference": "b9f72ab14efdb6b772f85041fa12f820dee8d55f", + "url": "https://api.github.com/repos/symfony/translation/zipball/dc89e16b44048ceecc879054e5b7f38326ab6cc5", + "reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5", "shasum": "" }, "require": { "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-mbstring": "~1.0", "symfony/translation-contracts": "^2.5|^3.0" }, @@ -2890,7 +2893,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v7.1.6" + "source": "https://github.com/symfony/translation/tree/v7.2.0" }, "funding": [ { @@ -2906,7 +2909,7 @@ "type": "tidelift" } ], - "time": "2024-09-28T12:35:13+00:00" + "time": "2024-11-12T20:47:56+00:00" }, { "name": "symfony/translation-contracts", @@ -3038,16 +3041,16 @@ }, { "name": "twig/twig", - "version": "v3.15.0", + "version": "v3.17.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "2d5b3964cc21d0188633d7ddce732dc8e874db02" + "reference": "677ef8da6497a03048192aeeb5aa3018e379ac71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/2d5b3964cc21d0188633d7ddce732dc8e874db02", - "reference": "2d5b3964cc21d0188633d7ddce732dc8e874db02", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/677ef8da6497a03048192aeeb5aa3018e379ac71", + "reference": "677ef8da6497a03048192aeeb5aa3018e379ac71", "shasum": "" }, "require": { @@ -3058,6 +3061,7 @@ "symfony/polyfill-php81": "^1.29" }, "require-dev": { + "phpstan/phpstan": "^2.0", "psr/container": "^1.0|^2.0", "symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0" }, @@ -3101,7 +3105,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.15.0" + "source": "https://github.com/twigphp/Twig/tree/v3.17.1" }, "funding": [ { @@ -3113,7 +3117,7 @@ "type": "tidelift" } ], - "time": "2024-11-17T15:59:19+00:00" + "time": "2024-12-12T09:58:10+00:00" }, { "name": "vlucas/phpdotenv", @@ -3286,5 +3290,5 @@ "ext-zip": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/kernel/CgRouteCollector.php b/kernel/CgRouteCollector.php index 6c3b6d5..f7bbd49 100644 --- a/kernel/CgRouteCollector.php +++ b/kernel/CgRouteCollector.php @@ -46,8 +46,16 @@ class CgRouteCollector extends RouteCollector //TODO } - public function console($route, $handler, array $filters = []): void + /** + * @param $route + * @param $handler + * @param array $filters + * @param array $additionalInfo + * @return void + */ + public function console($route, $handler, array $filters = [], array $additionalInfo = []): void { - $this->addRoute(Route::GET, $route, $handler, $filters); + $additionalInfo['type'] = "console"; + $this->addRoute(Route::GET, $route, $handler, $filters, $additionalInfo); } } \ No newline at end of file diff --git a/kernel/app_modules/tag/TagModule.php b/kernel/app_modules/tag/TagModule.php index 6411df8..1d12df8 100644 --- a/kernel/app_modules/tag/TagModule.php +++ b/kernel/app_modules/tag/TagModule.php @@ -30,8 +30,7 @@ class TagModule extends Module */ public function init(): void { - $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations/tag"); - $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations/tag_entity"); + $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); $this->menuService->createItem([ "label" => "Тэги", @@ -49,11 +48,17 @@ class TagModule extends Module OptionService::createFromParams("entity_tag_list", "{}", "Список тегов"); } + /** + * @throws \Exception + */ public function deactivate(): void { $this->menuService->removeItemBySlug("tag"); $this->menuService->removeItemBySlug("tag_settings"); + OptionService::removeOptionByKey("entity_tag_list"); + + $this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/tag/migrations"); } public function formInputs(string $entity, Model $model = null): void diff --git a/kernel/app_modules/tag/migrations/tag/2024_10_08_093710_create_tag_table.php b/kernel/app_modules/tag/migrations/2024_10_08_093710_create_tag_table.php similarity index 96% rename from kernel/app_modules/tag/migrations/tag/2024_10_08_093710_create_tag_table.php rename to kernel/app_modules/tag/migrations/2024_10_08_093710_create_tag_table.php index 37c4be5..810dece 100755 --- a/kernel/app_modules/tag/migrations/tag/2024_10_08_093710_create_tag_table.php +++ b/kernel/app_modules/tag/migrations/2024_10_08_093710_create_tag_table.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { + public string $migration; /** * Run the migrations. */ @@ -28,4 +29,5 @@ return new class extends Migration { \kernel\App::$db->schema->dropIfExists('tag'); } + }; diff --git a/kernel/app_modules/tag/migrations/tag_entity/2024_11_25_122506_create_tag_entity_table.php b/kernel/app_modules/tag/migrations/2024_11_25_122506_create_tag_entity_table.php similarity index 96% rename from kernel/app_modules/tag/migrations/tag_entity/2024_11_25_122506_create_tag_entity_table.php rename to kernel/app_modules/tag/migrations/2024_11_25_122506_create_tag_entity_table.php index 2006dfd..11c4c2a 100644 --- a/kernel/app_modules/tag/migrations/tag_entity/2024_11_25_122506_create_tag_entity_table.php +++ b/kernel/app_modules/tag/migrations/2024_11_25_122506_create_tag_entity_table.php @@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { + public string $migration; + /** * Run the migrations. */ diff --git a/kernel/console/Out.php b/kernel/console/Out.php index cc08182..7baa8ac 100644 --- a/kernel/console/Out.php +++ b/kernel/console/Out.php @@ -64,6 +64,11 @@ class Out echo $this->get($string, $foreground_color, $background_color) . "\n"; } + public function inLine($string, $foreground_color = null, $background_color = null): void + { + echo $this->get($string, $foreground_color, $background_color) ; + } + // Returns all foreground color names public function getForegroundColors() { diff --git a/kernel/console/controllers/MainController.php b/kernel/console/controllers/MainController.php index 5878dd6..31a55bf 100644 --- a/kernel/console/controllers/MainController.php +++ b/kernel/console/controllers/MainController.php @@ -16,10 +16,23 @@ class MainController extends ConsoleController public function actionHelp(): void { -// Debug::dd(App::$collector->getData()); -// foreach (App::$collector->getDescriptions() as $description){ -// $this->out->r($description, "green"); -// } + $routs = App::$collector->getData()->getStaticRoutes(); + foreach ($routs as $rout => $data){ + $additionalInfo = $data['GET'][3]; + if (isset($additionalInfo['description']) and $additionalInfo['type'] === "console"){ + $this->out->inLine($rout . " - ", "green"); + $this->out->inLine($additionalInfo['description'], 'yellow'); + $this->out->r(""); + if (isset($additionalInfo['params'])){ + foreach ($additionalInfo['params'] as $key => $param){ + $this->out->inLine($key . " - ", "green"); + $this->out->inLine($param, 'yellow'); + $this->out->r(""); + } + } + $this->out->r(""); + } + } } } \ No newline at end of file diff --git a/kernel/console/migrations/stubs/migration.stub b/kernel/console/migrations/stubs/migration.stub index 88fa2f3..16abcae 100644 --- a/kernel/console/migrations/stubs/migration.stub +++ b/kernel/console/migrations/stubs/migration.stub @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { + public string $migration; /** * Run the migrations. */ diff --git a/kernel/console/routs/cli.php b/kernel/console/routs/cli.php index 1d3f68f..da1b681 100644 --- a/kernel/console/routs/cli.php +++ b/kernel/console/routs/cli.php @@ -1,16 +1,26 @@ console("hello", [\kernel\console\controllers\MainController::class, "indexAction"]); App::$collector->console("help", [\kernel\console\controllers\MainController::class, "actionHelp"]); App::$collector->group(["prefix" => "migration"], callback: function (RouteCollector $router){ - App::$collector->console('run', [\kernel\console\controllers\MigrationController::class, 'actionRun']); - App::$collector->console('init', [\kernel\console\controllers\MigrationController::class, 'actionCreateMigrationTable']); - App::$collector->console('create', [\kernel\console\controllers\MigrationController::class, 'actionCreate']); - App::$collector->console('rollback', [\kernel\console\controllers\MigrationController::class, 'actionRollback']); + App::$collector->console('run', + [MigrationController::class, 'actionRun'], + additionalInfo: ['description' => 'Запуск существующих миграций'] + ); + App::$collector->console('init', + [MigrationController::class, 'actionCreateMigrationTable'], + additionalInfo: ['description' => 'Инициализация миграций'] + ); + App::$collector->console('create', + [MigrationController::class, 'actionCreate'], + additionalInfo: ['description' => 'Создание миграции', 'params' => ['--name' => 'Название миграции', '--path' => 'Путь по которому будет создана миграция']] + ); + App::$collector->console('rollback', [MigrationController::class, 'actionRollback']); }); App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCollector $router){ diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index ea08cd4..e0fc983 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -12,6 +12,7 @@ use kernel\models\Option; use kernel\modules\module_shop_client\services\ModuleShopClientService; use kernel\modules\user\service\UserService; use kernel\Request; +use kernel\services\MigrationService; use kernel\services\ModuleService; class ModuleController extends AdminController diff --git a/kernel/modules/post/PostModule.php b/kernel/modules/post/PostModule.php index b56971c..f45e55c 100644 --- a/kernel/modules/post/PostModule.php +++ b/kernel/modules/post/PostModule.php @@ -5,17 +5,22 @@ namespace kernel\modules\post; use kernel\helpers\Debug; use kernel\Module; use kernel\modules\menu\service\MenuService; +use kernel\services\MigrationService; class PostModule extends Module { public MenuService $menuService; + public MigrationService $migrationService; public function __construct() { $this->menuService = new MenuService(); + $this->migrationService = new MigrationService(); } public function init(): void { + $this->migrationService->runAtPath("{KERNEL_MODULES}/post/migrations"); + $this->menuService->createItem([ "label" => "Посты", "url" => "/admin/post", @@ -26,5 +31,6 @@ class PostModule extends Module public function deactivate(): void { $this->menuService->removeItemBySlug("post"); + $this->migrationService->rollbackAtPath("{KERNEL_MODULES}/post/migrations"); } } \ No newline at end of file diff --git a/kernel/modules/post/migrations/2024_09_23_130017_create_post_table.php b/kernel/modules/post/migrations/2024_09_23_130017_create_post_table.php index 6556a6a..4144a14 100644 --- a/kernel/modules/post/migrations/2024_09_23_130017_create_post_table.php +++ b/kernel/modules/post/migrations/2024_09_23_130017_create_post_table.php @@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { + public string $migration; + /** * Run the migrations. */ diff --git a/kernel/services/MigrationService.php b/kernel/services/MigrationService.php index aabee7b..d5f436a 100644 --- a/kernel/services/MigrationService.php +++ b/kernel/services/MigrationService.php @@ -36,4 +36,25 @@ class MigrationService } } + public function rollbackAtPath(string $path): void + { + $path = getConst($path); + try { + $filesystem = new Filesystem(); + $dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration'); + + $m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), $filesystem); + + $migrationFiles = $m->getMigrationFiles($path); + foreach ($migrationFiles as $name => $migrationFile){ + $migrationInstance = $filesystem->getRequire($migrationFile); + $migrationInstance->migration = $name; + $migrationInstance->down(); + $dmr->delete($migrationInstance); + } + } catch (\Exception $e) { + throw new \Exception('Не удалось откатить миграции'); + } + } + } \ No newline at end of file