Code Monkey home page Code Monkey logo

craft-db-paths's Introduction

Craft DB Paths Module

Skip to the usage instructions if you already know the story.

Background

Craft relies by default on the mysqldump and mysql executables to backup and restore databases. The default backup command looks like this:

mysqldump […options…] {database} > {file}'

The problem is that, while mysqldump might be available in the system, PHP running under a web request doesn’t know where to find it because it’s not in any directories specified in the PATH environmental variable. This is true when running locally with MAMP. It’s also true sometimes on EC2 instances when running MariaDB on RDS.

For this reason, Craft provides two configuration variables for you: backupCommand and restoreCommand. You can write your own command with the full path to the mysqldump executable. For MAMP it might be something like this:

/Applications/MAMP/Library/bin/mysqldump […options…] {database} > {file}

The thing is, Craft’s default dump command is really nice. It excludes unnecessary session, cache, and asset data. You can see how it’s built for MySQL in the Schema::defaultBackupCommand() method. What if you could just replace mysqldump with its full path and not have to roll your own command? That's what this module is for.

Usage

Installation

This is a module for Craft CMS, not a plugin available in Craft's Plugin Store. It is installed with composer on the command line.

Run the following command in the root of your project.

composer require samhernandez/craft-db-paths

Open /config/app.php, add the CraftDbPaths class as a module, and bootstrap it. Example:

return [
    'modules' => [
        'craft-db-paths' => \samhernandez\craftdbpaths\CraftDbPaths::class,
    ],
    'bootstrap' => ['craft-db-paths'],
];

Configuration

Add any of the following env vars to your .env file. Here is an example for MAMP on a Mac with MySQL.

PATH_TO_MYSQL=/Applications/MAMP/Library/bin/mysql
PATH_TO_MYSQLDUMP=/Applications/MAMP/Library/bin/mysqldump

If necessary, you can add paths for Postgres too.

PATH_TO_PSQL=/usr/local/bin/psql
PATH_TO_PGDUMP=/usr/local/bin/pg_dump

No configuration file is necesary, just env variables set in your .env or otherwise.

craft-db-paths's People

Contributors

samhernandez avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

craft-db-paths's Issues

Craft 4.0 support

Hi,

Would it be possible to also support Craft 4.0?
We want to upgrade a project that is using this plugin to Craft 4.0 but we get an error.

Thanks in advance,
Nele

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.