Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mount Last Db Bundle Laravel Package

antihero/mount-last-db-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require antihero/mount-last-db-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        Antihero\MountLastDbBundle\MountLastDbBundle::class => ['all' => true],
    ];
    
  2. Configuration Publish the default config:

    php bin/console config:dump-reference Antihero\MountLastDbBundle
    

    Update .env with your remote server credentials (SMB/SFTP) and local DB details:

    MOUNT_LAST_DB_REMOTE_SERVER=smb://user:pass@server/path
    MOUNT_LAST_DB_LOCAL_DB=your_local_db_name
    
  3. First Use Case Trigger a remote dump mount:

    php bin/console mount:last-db
    

    This fetches the latest .gz SQL dump from the remote server, decompresses it, and imports it into your local DB.


Implementation Patterns

Workflow Integration

  1. Automated Deployment Workflow

    • Use in a post-deploy script to sync production DB to staging/test:
      php bin/console mount:last-db --env=staging
      
    • Combine with Laravel’s artisan scheduler for nightly syncs:
      // app/Console/Kernel.php
      protected function schedule(Schedule $schedule)
      {
          $schedule->command('mount:last-db')->daily();
      }
      
  2. Custom Remote Sources Extend the bundle’s RemoteSourceInterface to support additional protocols (e.g., AWS S3):

    class S3Source implements RemoteSourceInterface
    {
        public function fetchLatestDump(): string
        {
            // AWS SDK logic to fetch latest dump
        }
    }
    

    Register the service in services.yaml:

    services:
        Antihero\MountLastDbBundle\RemoteSource\RemoteSourceInterface: '@app.s3_source'
    
  3. Conditional Mounting Check if a dump exists before mounting (e.g., in a CI/CD pipeline):

    php bin/console mount:last-db:check
    

Laravel-Specific Tips

  • Service Provider Binding Bind the bundle’s services in AppServiceProvider for custom logic:

    public function boot()
    {
        $this->app->bind(
            \Antihero\MountLastDbBundle\Service\DbService::class,
            function ($app) {
                return new CustomDbService($app);
            }
        );
    }
    
  • Event Listeners Trigger actions post-mount (e.g., cache clearing):

    // app/Providers/EventServiceProvider.php
    protected $listen = [
        'mount.last-db.success' => [
            \App\Listeners\ClearCache::class,
        ],
    ];
    

Gotchas and Tips

Common Pitfalls

  1. Permission Issues

    • SMB/SFTP: Ensure credentials in .env have read access to the remote dump directory.
    • Local DB: The PHP process must have write permissions to the DB (e.g., mysql.user privileges).
  2. File Locking

    • If the remote dump is still being written, the command may hang. Add a timeout or retry logic:
      # config/packages/antihero_mount_last_db.yaml
      mount_last_db:
          retry_attempts: 3
          retry_delay: 60
      
  3. Large Dumps

    • For >1GB dumps, increase PHP memory limits in php.ini:
      memory_limit = 2G
      max_execution_time = 3600
      

Debugging

  • Verbose Output Enable debug mode for detailed logs:
    php bin/console mount:last-db --env=local -v
    
  • Dry Run Test the fetch step without importing:
    php bin/console mount:last-db:fetch-only
    

Extension Points

  1. Custom Filename Patterns Override the dump filename regex in config:

    mount_last_db:
        dump_pattern: '^dump_(\d{4}-\d{2}-\d{2}).sql.gz$'
    
  2. Pre/Post-Mount Hooks Use Symfony events to inject logic:

    // src/EventListener/MountListener.php
    public function onMountSuccess(MountSuccessEvent $event)
    {
        // Run custom logic after mount
    }
    

    Register the listener in services.yaml:

    services:
        App\EventListener\MountListener:
            tags:
                - { name: kernel.event_listener, event: mount.last-db.success }
    
  3. Database-Specific Quirks

    • MySQL: Add --single-transaction to mysql CLI flags to avoid locks:
      mount_last_db:
          mysql_flags: ['--single-transaction']
      
    • PostgreSQL: Use pg_restore for custom formats:
      mount_last_db:
          db_engine: pgsql
          restore_flags: ['--clean', '--if-exists']
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log