mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some experimental commands for DB creation.
This commit is contained in:
parent
07623335f7
commit
cd2e74a476
@ -55,6 +55,7 @@ fi
|
|||||||
#env $(grep -v "^\#" .env | xargs)
|
#env $(grep -v "^\#" .env | xargs)
|
||||||
php artisan cache:clear
|
php artisan cache:clear
|
||||||
php artisan migrate --seed
|
php artisan migrate --seed
|
||||||
|
php artisan firefly-iii:create-database
|
||||||
php artisan firefly-iii:decrypt-all
|
php artisan firefly-iii:decrypt-all
|
||||||
|
|
||||||
# there are 13 upgrade commands
|
# there are 13 upgrade commands
|
||||||
|
71
app/Console/Commands/CreateDatabase.php
Normal file
71
app/Console/Commands/CreateDatabase.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use PDO;
|
||||||
|
use PDOException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CreateDatabase
|
||||||
|
*/
|
||||||
|
class CreateDatabase extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Tries to create the database if it doesn\'t exist yet.';
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'firefly-iii:create-database';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if ('mysql' !== env('DB_CONNECTION')) {
|
||||||
|
$this->info('This command currently applies to MySQL connections only.');
|
||||||
|
}
|
||||||
|
// try to set up a raw connection:
|
||||||
|
$dsn = sprintf('mysql:host=%s;charset=utf8mb4', env('DB_HOST'));
|
||||||
|
$options = [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
|
PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$pdo = new PDO($dsn, env('DB_USERNAME'), env('DB_PASSWORD'), $options);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$this->error(sprintf('Error when connecting to DB: %s', $e->getMessage()));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
// with PDO, try to list DB's (
|
||||||
|
$stmt = $pdo->prepare('SHOW DATABASES WHERE `Database` = ?');
|
||||||
|
$stmt->execute([env('DB_DATABASE')]);
|
||||||
|
$result = $stmt->fetch();
|
||||||
|
if (false === $result) {
|
||||||
|
$this->error(sprintf('Database "%s" does not exist.', env('DB_DATABASE')));
|
||||||
|
|
||||||
|
// try to create it.
|
||||||
|
$stmt = $pdo->query(sprintf('CREATE DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;', env('DB_DATABASE')));
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->fetch();
|
||||||
|
$this->info(sprintf('Created database "%s"', env('DB_DATABASE')));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$this->info(sprintf('Database "%s" exists.', env('DB_DATABASE')));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -87,7 +87,8 @@
|
|||||||
"pragmarx/google2fa": "6.1.3",
|
"pragmarx/google2fa": "6.1.3",
|
||||||
"pragmarx/google2fa-laravel": "1.*",
|
"pragmarx/google2fa-laravel": "1.*",
|
||||||
"pragmarx/recovery": "^0.1.0",
|
"pragmarx/recovery": "^0.1.0",
|
||||||
"rcrowe/twigbridge": "0.9.*"
|
"rcrowe/twigbridge": "0.9.*",
|
||||||
|
"ext-pdo": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-ide-helper": "2.*",
|
"barryvdh/laravel-ide-helper": "2.*",
|
||||||
|
Loading…
Reference in New Issue
Block a user