Skip to content

Instantly share code, notes, and snippets.

@ariera
Created January 26, 2017 14:57
Show Gist options
  • Save ariera/87feebe6f34b6a2ce7cdc64773a0098e to your computer and use it in GitHub Desktop.
Save ariera/87feebe6f34b6a2ce7cdc64773a0098e to your computer and use it in GitHub Desktop.
<?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