53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Lucent\Setup\Step;
|
||
|
|
|
||
|
|
use Illuminate\Database\QueryException;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Lucent\Setup\Data\SetupStep;
|
||
|
|
|
||
|
|
class DatabaseSetupStep implements IStep
|
||
|
|
{
|
||
|
|
|
||
|
|
public function __invoke(): SetupStep
|
||
|
|
{
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$name = "Database Connection";
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$databaseConfig = config('database.connections.lucentdb');
|
||
|
|
if(empty($databaseConfig)) {
|
||
|
|
$instructions = <<<EOD
|
||
|
|
# You need to setup a database connection for lucentdb in database.php config. You can choose either sqlite or pgsql
|
||
|
|
# example:
|
||
|
|
|
||
|
|
'connections' => [
|
||
|
|
'lucentdb' => [
|
||
|
|
'driver' => 'sqlite',
|
||
|
|
'url' => env('LUCENT_DATABASE_URL'),
|
||
|
|
'database' => env('LUCENT_DB_DATABASE', database_path('database.sqlite')),
|
||
|
|
'prefix' => '',
|
||
|
|
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||
|
|
],
|
||
|
|
EOD;
|
||
|
|
return SetupStep::makeFail($name, $instructions);
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
DB::connection("lucentdb")->table("records")->get();
|
||
|
|
}catch (QueryException $e) {
|
||
|
|
$instructions = <<<EOD
|
||
|
|
# Make sure you run:
|
||
|
|
php artisan lucent:setup-db
|
||
|
|
EOD;
|
||
|
|
return SetupStep::makeFail($name, $instructions);
|
||
|
|
}
|
||
|
|
|
||
|
|
return SetupStep::makeSuccess($name, "Database Connection successfully created");
|
||
|
|
}
|
||
|
|
}
|