Skip to content

Instantly share code, notes, and snippets.

@msonowal
Forked from greglamb/DbSchemadumpCommand.php
Created November 2, 2015 11:12
Show Gist options
  • Save msonowal/55e63945bdedb3d77075 to your computer and use it in GitHub Desktop.
Save msonowal/55e63945bdedb3d77075 to your computer and use it in GitHub Desktop.
Laravel DbSchemadumpCommand
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Process\Process;
class DbSchemadumpCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'db:schemadump';
/**
* The console command description.
*
* @var string
*/
protected $description = 'save schema';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$config = Config::get('database.connections.'.Config::get('database.default'));
$command = sprintf('PGPASSWORD=%s pg_dump --no-acl --schema-only --verbose -N "public" --no-owner -h %s -U %s %s > %s',
escapeshellarg($config['password']),
escapeshellarg($config['host']),
escapeshellarg($config['username']),
escapeshellarg($config['database']),
escapeshellarg(app_path().'/database/backup/pgschema_'.date("YmdHis").'.'.uniqid().'.sql')
);
$process = new Process($command);
$process->run();
echo "Executed command : ".$command."\n";
if ($process->isSuccessful()) {
return true;
} else {
return $process->getErrorOutput();
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [];
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment