Skip to content

Instantly share code, notes, and snippets.

@henno
Last active March 28, 2025 19:45
Show Gist options
  • Save henno/14e18a285e5d3287e84dcd09812fc5e6 to your computer and use it in GitHub Desktop.
Save henno/14e18a285e5d3287e84dcd09812fc5e6 to your computer and use it in GitHub Desktop.
Cross-compatible MySQL/MariaDB script ideal for quick resets and creating new dumps while developing, featuring automatic database name detection from config files or current directory name
https://github.com/henno/refreshdb
@henno
Copy link
Author

henno commented Mar 29, 2024

Installation script for Powershell:

# Append $HOME\bin to PATH if it's not already included
if (-not ($env:PATH -split ';' -contains "$HOME\bin")) { [Environment]::SetEnvironmentVariable('PATH', ($env:PATH.TrimEnd(';') + ";$HOME\bin"), 'User') }

# Ensure the bin directory exists
$binPath = Join-Path -Path $HOME -ChildPath "bin"
if (-not (Test-Path -Path $binPath)) { New-Item -ItemType Directory -Path $binPath -Force }

# Download the script to the bin directory
$scriptUrl = "https://raw.githubusercontent.com/henno/refreshdb/refs/heads/main/refreshdb.php"
$destinationPath = Join-Path -Path $binPath -ChildPath "refreshdb.php"
Invoke-WebRequest -Uri $scriptUrl -OutFile $destinationPath

# Create a wrapper db.bat to avoid having to preceed the php file with the full path to php.exe 
Set-Content -Path "$HOME\bin\db.bat" -Value @'
@echo off
set "PHP_EXECUTABLE=C:\xampp824\php\php.exe"
set "SCRIPT_PATH=c:\users\user\bin\refreshdb.php"

%PHP_EXECUTABLE% %SCRIPT_PATH% %*
'@

Restart all terminals and use the script in the folder of your project:
db --restore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment