Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove SilverStripe test databases
<?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;
@wilr

This comment has been minimized.

Copy link

commented Jun 13, 2012

And dev/tests/cleanupdb doesn't do this?

@stojg

This comment has been minimized.

Copy link
Owner Author

commented Jun 13, 2012

Sneaky Will, I did not know that, :D thanks!

@Firesphere

This comment has been minimized.

Copy link

commented Jun 7, 2017

Can this please pretty please be documented somewhere? I have to google this gist every time :|

@Firesphere

This comment has been minimized.

Copy link

commented Jun 7, 2017

Also, moved to /dev/tasks/ in SS4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.