darvinstudio/darvin-databaser-bundle
Installation:
composer require darvinstudio/darvin-databaser-bundle
Register the bundle in config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3/legacy):
return [
// ...
Darvin\DatabaserBundle\DarvinDatabaserBundle::class => ['all' => true],
];
First Use Case: Pull a remote database locally (e.g., staging → development):
php bin/console databaser:pull root@staging.example.com /var/www/staging /var/www/local
Push local changes to a remote (e.g., development → staging):
php bin/console databaser:push root@staging.example.com /var/www/staging /var/www/local
Key Files:
config/packages/darvin_databaser.yaml (if created; check for defaults).src/Kernel.php (Symfony 4+) or AppKernel.php (Symfony 3) for bundle registration.var/log/ for debugging output (enable verbose mode with -v).CI/CD Integration:
pre-deploy hook in GitHub Actions):
- name: Sync Staging DB
run: php bin/console databaser:pull ${{ secrets.STAGING_USER }}@${{ secrets.STAGING_HOST }}:/path/remote /path/local
Environment-Specific Config:
config/packages/darvin_databaser.yaml:
darvin_databaser:
default_port: 2222 # Custom SSH port
timeout: 300 # Increase for large databases
Pre/Post-Processing:
// src/EventListener/DatabaserListener.php
use Darvin\DatabaserBundle\Event\DatabaserEvent;
public function onPrePull(DatabaserEvent $event) {
$this->runMigrations(); // Custom logic
}
services.yaml:
services:
App\EventListener\DatabaserListener:
tags: ['kernel.event_listener', 'databaser.pre_pull']
Scheduled Syncs:
CronBundle or laravel-schedule (if using Laravel’s scheduler) to automate daily syncs:
* * * * * php bin/console databaser:pull root@backup.example.com /backup/db /local/db
~/.ssh/ with restricted permissions (chmod 600).ParameterBag to inject paths dynamically:
$this->container->getParameter('ssh_key_path');
--exclude flags to skip non-critical tables:
php bin/console databaser:pull --exclude=logs,temp root@host /remote /local
-n (dry run) to validate paths/permissions:
php bin/console databaser:pull -n root@host /remote /local
Permission Issues:
Permission denied (publickey) or Failed to open local file.~/.ssh/authorized_keys on the remote.chmod -R 755 /path/local).Port Conflicts:
Connection timed out or Port 22: Connection refused.-P if the remote uses a non-standard SSH port (e.g., -P 2222).ufw allow 2222 on Ubuntu).Database Locks:
Table is locked or Deadlock found.--force (if supported).--single-transaction to avoid locks:
php bin/console databaser:pull --option="--single-transaction" root@host /remote /local
Path Mismatches:
No such file or directory for remote/local paths./var/www/ instead of ./).ssh root@host "ls /var/www/"
-v or -vvv for detailed logs:
php bin/console databaser:pull -vvv root@host /remote /local
config/packages/monolog.yaml to write to a file:
handlers:
databaser:
type: stream
path: "%kernel.logs_dir%/databaser.log"
level: debug
Custom Commands: Extend the base command to add features (e.g., diff tools):
// src/Command/CustomDatabaserCommand.php
use Darvin\DatabaserBundle\Command\AbstractDatabaserCommand;
class CustomDatabaserCommand extends AbstractDatabaserCommand {
protected function configure() {
$this->setName('databaser:diff')
->addArgument('remote', InputArgument::REQUIRED);
}
protected function execute(InputInterface $input, OutputInterface $output) {
// Custom logic (e.g., call `diff` tool)
}
}
Event Dispatching:
Listen for databaser.pre_pull, databaser.post_push, etc., to inject logic:
// src/EventSubscriber/DatabaserSubscriber.php
use Darvin\DatabaserBundle\Event\DatabaserEvent;
class DatabaserSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
DatabaserEvent::PRE_PULL => 'onPrePull',
];
}
public function onPrePull(DatabaserEvent $event) {
$event->setOption('--exclude', 'cache');
}
}
Configuration Overrides: Dynamically override settings via environment variables:
# config/packages/darvin_databaser.yaml
darvin_databaser:
port: "%env(DATABASER_PORT)%"
timeout: "%env(int:DATABASER_TIMEOUT)%"
mysqldump -u root -p local_db > local_backup.sql
uploads/) to speed up syncs:
php bin/console databaser:pull --exclude="uploads/*" root@host /remote /local
--progress (if supported) or log file sizes pre/post-sync to track changes:
$event->setOption('--progress', true);
How can I help you explore Laravel packages today?