Skip to content
Browse files

Prompt to backup first and log commands

  • Loading branch information...
1 parent 4e557b4 commit 200c738c3bf0ca008f078202c88a929d7cd9ba49 @jwheare committed Mar 11, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 core/dbmigrationscript.class.php
View
11 core/dbmigrationscript.class.php
@@ -14,10 +14,17 @@ public function run () {
if (count($migrations)) {
$this->out("Loading migrations:\n");
natcasesort($migrations);
+ // Prompt
+ $this->out("\n" . implode("\n$migrationDir/", $migrations) . "\n\nAre you happy to run these SQL migrations on the `" . MYSQL_DB . "` database now?\nProbably wise to backup your database first.\n[Y/n]: ");
+ $input = strtolower(trim(fgets(STDIN)));
+ if ($input && ($input[0] == 'n' || $input == 0)) {
+ $this->end();
+ }
foreach ($migrations as $migration) {
try {
- $this->out("$migration\n");
- service('db')->execute(file_get_contents("$migrationDir/$migration"));
+ $commands = file_get_contents("$migrationDir/$migration");
+ $this->out("\n$migration\n$commands\n");
+ service('db')->execute($commands);
} catch (PDOException $e) {
if ($e->errorInfo[1] != 1060) { // Duplicate column
throw $e;

0 comments on commit 200c738

Please sign in to comment.
Something went wrong with that request. Please try again.