Giter Site home page Giter Site logo

laravel-database-tools's Introduction

Laravel Database Tools

The "missing" database toolset for Laravel. A set of commonly used Database Tools for Laravel.

With this package you can:

  • Create a database (if it does not exist)
  • Dump from another database to file
  • Get and unzip from a database backup created by the Spatie Backup package
  • Import from file
  • Update the charset and collation
  • Fixes the "no such function" error by giving SQLite MySQL compatibility by creating the missing function using PDO for SQLite using PHP functions.

Install

Install the package into your Laravel application:

  • composer require --dev jpswade/laravel-database-tools

Note: It's wise to only install these tools in development by default, as it's rare you should need them in a production environment.

Configure

Publish and customise your own dbtools.php file:

  • php artisan vendor:publish --provider="Jpswade\LaravelDatabaseTools\ServiceProvider" --tag="config"

This allows you to set the source database and/or filesystem for the backup.

  • dbtools.database - Define the source database for the db:dump command, similar to Laravel databases config.
  • dbtools.filesystem - Define the source filesystem for the db:getFromBackup command, similar to Laravel filesystems config.
  • dbtools.filesystem.path - Define the path for the db:getFromBackup command.
  • dbtools.import - Here you can define the method (command or normal) for the db:importFromFile command.

Note:

  • The db:getFromBackup command falls back to the spatie/laravel-backup package for configuration.

Usage

The commands are:

  • db:create - Creates the database schema.
  • db:dump - Fetch a copy of the latest database from the configured server.
  • db:getFromBackup - Download database backup file from backup.
  • db:importFromFile {file?} - Import data from a sql file into a database.
  • db:charset - Changes the charset and collation to whatever the database is set to use.

SQLite MySQL Compatability Provider

For testing you can add the provider to your Test:

    protected function registerServiceProviders(): void
    {
        $this->app->register(SqliteMysqlCompatibilityProvider::class);
    }

    protected function setUp(): void
    {
        parent::setUp();

        $this->registerServiceProviders();
    }

In production, follow the usual Registering Providers instructions:

In config/app.php, find the providers array and add:

'providers' => [
    // Other Service Providers
 
    Jpswade\LaravelDatabaseTools\SqliteMysqlCompatibilityProvider::class,
],

Limitations

These are limitations you'll come across if you use certain commands:

  • The db:getFromBackup command relies on the league/flysystem-aws-s3-v3 "^1.0" package, when you use the Amazon S3 Driver as per the Laravel docs.
  • The db:dump command depends on spatie/db-dumper.
  • The commands have only been tested to work with MySQL at the moment, but could be extended to others.

Troubleshooting

Class 'League\Flysystem\AwsS3v3\AwsS3Adapter' not found

% composer require league/flysystem-aws-s3-v3:~1.0

laravel-database-tools's People

Contributors

jpswade avatar

Stargazers

Blaze avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

geekwolverine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.