Created
January 26, 2017 14:57
-
-
Save ariera/87feebe6f34b6a2ce7cdc64773a0098e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Illuminate\Support\Facades\DB; | |
use Illuminate\Support\Facades\Config; | |
class SchemaDumpCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'db:schema:dump'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Dumps the current database schema to the database directory (currently only PostgerSQL supported)'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$databaseName = Config::get('database.connections.'.Config::get('database.default').'.database'); | |
$dumpCommand = 'pg_dump -s '.$databaseName.' > '.database_path('schema.sql'); | |
return exec($dumpCommand); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment