Created
June 13, 2012 00:22
-
-
Save stojg/2920975 to your computer and use it in GitHub Desktop.
Remove SilverStripe test databases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This script will drop all the databases that contains this string 'tmpdb'. | |
* Those databases are likely to be left over from a SilverStripe test run | |
* Usage: Make sure you change the db connection string below and run the | |
* script like: | |
* php remove-tmp-db.php | |
*/ | |
// Change this to your db connection | |
$host = '127.0.0.1'; | |
$user = 'root'; | |
$password = ''; | |
error_reporting(E_ALL | E_STRICT); | |
$dbConn = mysql_connect($host, $user, $password); | |
$result = mysql_query('SHOW DATABASES;'); | |
$toDrop = array(); | |
while($row = mysql_fetch_assoc($result)) { | |
$schema = $row['Database']; | |
if(stristr($schema,'tmpdb')) { | |
$toDrop[] = $schema; | |
} | |
} | |
for($idx=1; $idx <= count($toDrop); $idx++) { | |
$schema = $toDrop[($idx-1)]; | |
echo '[-] '.$idx.'/'.count($toDrop).' Dropping '.$schema.PHP_EOL; | |
mysql_query('DROP DATABASE '.$schema); | |
} | |
echo '[+] Done, all temporary databases has been dropped.'.PHP_EOL; |
Can this please pretty please be documented somewhere? I have to google this gist every time :|
Also, moved to /dev/tasks/
in SS4
I love when 2012 Will helps 2021 Will. For reference and anyone googling in SilverStripe 4 this is now ./vendor/bin/sake dev/tasks/CleanupTestDatabasesTask
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sneaky Will, I did not know that, :D thanks!