Files
core/app/Console/Commands/InitDatabaseSchema.php

55 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class InitDatabaseSchema extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:init';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Init database structure';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
do {
$schema = $this->ask('Path to database schema file', 'database/schema.sql');
} while (!file_exists($schema));
DB::unprepared(file_get_contents($schema));
$this->call('migrate');
$this->call('db:seed');
$this->line('Database successfully initialized.');
}
}