2024-09-23 17:03:42 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace kernel\services;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
|
|
|
|
|
use Illuminate\Database\Migrations\Migrator;
|
|
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
|
use kernel\App;
|
2024-10-08 13:16:57 +03:00
|
|
|
|
use kernel\helpers\Debug;
|
2024-09-23 17:03:42 +03:00
|
|
|
|
|
|
|
|
|
class MigrationService
|
|
|
|
|
{
|
|
|
|
|
protected ModuleService $moduleService;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->moduleService = new ModuleService();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
public function runAtPath(string $path = ROOT_DIR . '/migrations'): array
|
|
|
|
|
{
|
2024-10-08 13:16:57 +03:00
|
|
|
|
$path = getConst($path);
|
2024-11-25 16:58:01 +03:00
|
|
|
|
// Debug::dd($path);
|
2024-10-08 13:16:57 +03:00
|
|
|
|
|
2024-09-23 17:03:42 +03:00
|
|
|
|
try {
|
|
|
|
|
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
|
|
|
|
|
|
|
|
|
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
|
|
|
|
|
|
|
|
|
return $m->run($path);
|
|
|
|
|
} catch (\Exception $e) {
|
2024-11-25 16:58:01 +03:00
|
|
|
|
throw new \Exception('Не удалось поднять миграции');
|
2024-09-23 17:03:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|