admin init command

This commit is contained in:
2024-09-23 17:03:42 +03:00
parent 0f05bc2391
commit a48088581f
25 changed files with 376 additions and 34 deletions

View File

@ -19,6 +19,7 @@ use kernel\services\ModuleService;
class MigrationController extends ConsoleController
{
protected ModuleService $moduleService;
public function __construct()
{
parent::__construct();
@ -35,8 +36,7 @@ class MigrationController extends ConsoleController
$table->integer('batch');
});
$this->out->r("Success", 'green');
}
catch (\Exception $e){
} catch (\Exception $e) {
$this->out->r($e->getMessage(), 'red');
}
}
@ -60,7 +60,7 @@ class MigrationController extends ConsoleController
);
$this->out->r(basename($res) . " created", 'green');
} catch (\Exception $e) {
$this->out->r('Message: ' .$e->getMessage(), 'red');
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
@ -71,15 +71,18 @@ class MigrationController extends ConsoleController
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
//$migrationPaths = [ROOT_DIR . '/migrations'];
if (\kernel\App::$db->schema->hasTable('option')) {
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
} else {
$migrationPaths = [ROOT_DIR . '/migrations'];
}
$res = $m->run($migrationPaths);
foreach ($res as $re){
foreach ($res as $re) {
$this->out->r(basename($re), 'green');
}
}
catch (\Exception $e){
$this->out->r('Message: ' .$e->getMessage(), 'red');
} catch (\Exception $e) {
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
@ -94,12 +97,11 @@ class MigrationController extends ConsoleController
$migrationPaths = [ROOT_DIR . '/migrations'];
$res = $m->rollback($migrationPaths, ['step' => $step]);
print_r($step);
foreach ($res as $re){
foreach ($res as $re) {
$this->out->r(basename($re), 'green');
}
}
catch (\Exception $e){
$this->out->r('Message: ' .$e->getMessage(), 'red');
} catch (\Exception $e) {
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
}