Cleanup of database reset and cleanup

This commit is contained in:
Nabeel Shahzad 2017-07-13 13:45:59 -05:00
parent 81667a0184
commit 9b573709e9
9 changed files with 119 additions and 57 deletions

View File

@ -7,13 +7,11 @@ APP_URL=http://localhost
APP_SETTINGS_STORE=json
DB_CONNECTION=local
DB_HOST=localhost
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=
DB_DATABASE=phpvms
DB_USERNAME=
DB_PASSWORD=
CACHE_DRIVER=array
CACHE_PREFIX=
PHPVMS_CURRENCY=dollar

View File

@ -5,11 +5,11 @@ APP_LOG_LEVEL=debug
APP_URL=http://localhost
APP_SETTINGS_STORE=json
DB_CONNECTION=local
DB_HOST=localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=
DB_DATABASE=phpvms
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=array

View File

@ -24,10 +24,12 @@
</option>
<option name="migratedIntoUserSpace" value="true" />
</inspection_tool>
<inspection_tool class="PhpSignatureMismatchDuringInheritanceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
<inspection_tool class="SuspiciousAssignmentsInspection" enabled="false" level="ERROR" enabled_by_default="false" />
</profile>
</component>

View File

@ -5,10 +5,14 @@ php:
- '7.1'
# - hhvm
services:
- mysql
before_install:
- mysql -e 'CREATE DATABASE IF NOT EXISTS phpvms;'
before_script:
#- cp .env.travis .env
- cp .env.travis .env
#- mysql -e 'create database phpvms_test;'
- composer self-update
- make build

View File

@ -25,11 +25,10 @@ clean:
@php artisan optimize
@php artisan route:clear
@php artisan config:clear
@rm -f database/*.sqlite
.PHONY: reset
reset: clean
@sqlite3 database/testing.sqlite ""
@php artisan database:create --reset
@php artisan migrate:refresh --seed
.PHONY: db

View File

@ -0,0 +1,102 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class CreateDatabase extends Command
{
protected $signature = 'database:create {--reset}';
protected $description = 'Create a database';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
protected function runCommand($cmd)
{
$cmd = join(' ', $cmd);
$this->info('Running "' . $cmd . '"');
$proc = new Process($cmd);
$proc->run();
if (!$proc->isSuccessful()) {
throw new ProcessFailedException($proc);
}
echo $proc->getOutput();
}
protected function create_mysql($dbkey)
{
$mysql_cmd = [
'mysql',
'-u' . config($dbkey . 'username'),
'-p' . config($dbkey . 'password'),
'-h' . config($dbkey . 'host'),
'-P' . config($dbkey . 'port'),
];
if ($this->option('reset')) {
$cmd = array_merge(
$mysql_cmd,
["-e 'DROP DATABASE ".config($dbkey . 'database')."'"]
);
$this->runCommand($cmd);
}
$cmd = array_merge(
$mysql_cmd,
["-e 'CREATE DATABASE IF NOT EXISTS " . config($dbkey . 'database') . "'"]
);
$this->runCommand($cmd);
}
protected function create_sqlite($dbkey)
{
if ($this->option('reset')) {
$cmd = ['rm', '-rf', config($dbkey . 'database')];
$this->runCommand($cmd);
}
$cmd = [
'sqlite3',
config($dbkey . 'database'),
'""',
];
$this->runCommand($cmd);
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Using connection "'.config('database.default').'"');
$dbkey = 'database.connections.' . config('database.default').'.';
if(config($dbkey.'driver') === 'mysql') {
$this->create_mysql($dbkey);
}
elseif (config($dbkey . 'driver') === 'sqlite') {
$this->create_sqlite($dbkey);
}
}
}

View File

@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
//
Commands\CreateDatabase::class,
];
/**

View File

@ -9,7 +9,7 @@ return [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'phpvms'),
'username' => env('DB_USERNAME', 'phpvms'),

View File

@ -32,48 +32,5 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="PHP" type="php">
<CLASSES>
<root url="file://$APPLICATION_HOME_DIR$/bin" />
<root url="file://$MODULE_DIR$/vendor/chrisbjr/api-guard" />
<root url="file://$MODULE_DIR$/vendor/dompdf/dompdf" />
<root url="file://$MODULE_DIR$/vendor/ellipsesynergie/api-response" />
<root url="file://$MODULE_DIR$/vendor/jeremeamia/SuperClosure" />
<root url="file://$MODULE_DIR$/vendor/league/fractal" />
<root url="file://$MODULE_DIR$/vendor/maatwebsite/excel" />
<root url="file://$MODULE_DIR$/vendor/nikic/php-parser" />
<root url="file://$MODULE_DIR$/vendor/phenx/php-font-lib" />
<root url="file://$MODULE_DIR$/vendor/phenx/php-svg-lib" />
<root url="file://$MODULE_DIR$/vendor/phpoffice/phpexcel" />
<root url="file://$MODULE_DIR$/vendor/spatie/fractalistic" />
<root url="file://$MODULE_DIR$/vendor/spatie/laravel-fractal" />
<root url="file://$MODULE_DIR$/vendor/symfony/polyfill-php56" />
<root url="file://$MODULE_DIR$/vendor/symfony/polyfill-util" />
<root url="file://$MODULE_DIR$/vendor/webpatser/laravel-uuid" />
<root url="file://$MODULE_DIR$/vendor/yajra/laravel-datatables-oracle" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$APPLICATION_HOME_DIR$/bin" />
<root url="file://$MODULE_DIR$/vendor/chrisbjr/api-guard" />
<root url="file://$MODULE_DIR$/vendor/dompdf/dompdf" />
<root url="file://$MODULE_DIR$/vendor/ellipsesynergie/api-response" />
<root url="file://$MODULE_DIR$/vendor/jeremeamia/SuperClosure" />
<root url="file://$MODULE_DIR$/vendor/league/fractal" />
<root url="file://$MODULE_DIR$/vendor/maatwebsite/excel" />
<root url="file://$MODULE_DIR$/vendor/nikic/php-parser" />
<root url="file://$MODULE_DIR$/vendor/phenx/php-font-lib" />
<root url="file://$MODULE_DIR$/vendor/phenx/php-svg-lib" />
<root url="file://$MODULE_DIR$/vendor/phpoffice/phpexcel" />
<root url="file://$MODULE_DIR$/vendor/spatie/fractalistic" />
<root url="file://$MODULE_DIR$/vendor/spatie/laravel-fractal" />
<root url="file://$MODULE_DIR$/vendor/symfony/polyfill-php56" />
<root url="file://$MODULE_DIR$/vendor/symfony/polyfill-util" />
<root url="file://$MODULE_DIR$/vendor/webpatser/laravel-uuid" />
<root url="file://$MODULE_DIR$/vendor/yajra/laravel-datatables-oracle" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>