Extract helpers and other requires
This commit is contained in:
parent
79aaa21040
commit
0f28f951a3
3 changed files with 60 additions and 11 deletions
14
bin/migrate
14
bin/migrate
|
|
@ -1,15 +1,7 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Ensure database file exists
|
||||
$dbPath = __DIR__ . '/../storage/database.sqlite';
|
||||
if (!file_exists($dbPath)) {
|
||||
touch($dbPath);
|
||||
}
|
||||
|
||||
require __DIR__ . '/../bootstrap/database.php';
|
||||
require __DIR__ . '/../bootstrap/autoload.php';
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
|
||||
|
|
@ -20,8 +12,8 @@ $migrator = new Migrator($repository, $capsule->getDatabaseManager(), new Filesy
|
|||
|
||||
if (! $repository->repositoryExists()) {
|
||||
$repository->createRepository();
|
||||
echo "Migration table created.\n";
|
||||
logger('migration')->info("Migration table created");
|
||||
}
|
||||
|
||||
$migrator->run(__DIR__ . '/../database/migrations');
|
||||
echo "Migrations complete.\n";
|
||||
logger('migration')->info("Migrations completed successfully");
|
||||
|
|
|
|||
26
bootstrap/autoload.php
Normal file
26
bootstrap/autoload.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
// Load Composer autoloader
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Load helper functions
|
||||
require __DIR__ . '/helpers.php';
|
||||
|
||||
// Ensure storage directories exist
|
||||
$storageDir = __DIR__ . '/../storage';
|
||||
$logsDir = $storageDir . '/logs';
|
||||
if (!is_dir($storageDir)) {
|
||||
mkdir($storageDir, 0755, true);
|
||||
}
|
||||
if (!is_dir($logsDir)) {
|
||||
mkdir($logsDir, 0755, true);
|
||||
}
|
||||
|
||||
// Ensure database file exists
|
||||
$dbPath = $storageDir . '/database.sqlite';
|
||||
if (!file_exists($dbPath)) {
|
||||
touch($dbPath);
|
||||
}
|
||||
|
||||
// Load database configuration
|
||||
require __DIR__ . '/database.php';
|
||||
31
bootstrap/helpers.php
Normal file
31
bootstrap/helpers.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
No <?php
|
||||
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
|
||||
if (!function_exists('base_path')) {
|
||||
function base_path($path = '') {
|
||||
return __DIR__ . '/../' . $path;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('logger')) {
|
||||
function logger(string $channel = 'app'): Logger {
|
||||
static $loggers = [];
|
||||
|
||||
if (!isset($loggers[$channel])) {
|
||||
$logger = new Logger($channel);
|
||||
|
||||
// Ensure logs directory exists
|
||||
$logsDir = __DIR__ . '/../storage/logs';
|
||||
if (!is_dir($logsDir)) {
|
||||
mkdir($logsDir, 0755, true);
|
||||
}
|
||||
|
||||
$logger->pushHandler(new StreamHandler($logsDir . "/{$channel}.log", Logger::INFO));
|
||||
$loggers[$channel] = $logger;
|
||||
}
|
||||
|
||||
return $loggers[$channel];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue