Пример #1
0
function main($args)
{
    //input sanity check
    if (!is_array($args) || is_array($args) && !array_key_exists('name', $args)) {
        print_help(true);
    }
    $migration_name = $args['name'];
    //clear any filesystem stats cache
    clearstatcache();
    //check to make sure our migration directory exists
    if (!is_dir(RUCKUSING_MIGRATION_DIR)) {
        die_with_error("ERROR: migration directory '" . RUCKUSING_MIGRATION_DIR . "' does not exist. Specify MIGRATION_DIR in config/config.inc.php and try again.");
    }
    //generate a complete complete
    $highest_version = Ruckusing_VersionUtil::get_highest_migration(RUCKUSING_MIGRATION_DIR);
    $next_version = Ruckusing_VersionUtil::to_migration_number($highest_version + 1);
    $klass = Ruckusing_NamingUtil::camelcase($migration_name);
    $file_name = $next_version . '_' . $klass . '.php';
    $full_path = realpath(RUCKUSING_MIGRATION_DIR) . '/' . $file_name;
    $template_str = get_template($klass);
    //check to make sure our destination directory is writable
    if (!is_writable(RUCKUSING_MIGRATION_DIR . '/')) {
        die_with_error("ERROR: migration directory '" . RUCKUSING_MIGRATION_DIR . "' is not writable by the current user. Check permissions and try again.");
    }
    //write it out!
    $file_result = file_put_contents($full_path, $template_str);
    if ($file_result === FALSE) {
        die_with_error("Error writing to migrations directory/file. Do you have sufficient privileges?");
    } else {
        echo "\nCreated migration: {$file_name}\n\n";
    }
}
 public function execute($args)
 {
     $output = "";
     if (!$this->adapter->supports_migrations()) {
         die("This database does not support migrations.");
     }
     $this->task_args = $args;
     echo "Started: " . date('Y-m-d g:ia T') . "\n\n";
     echo "[db:migrate]: \n";
     try {
         // Check that the schema_info table exists, and if not, automatically create it
         $this->verify_environment();
         $goto_version = 1;
         //$this->extract_args($args);
         $db_version = $this->get_db_version();
         //did the user specify a version?
         if (array_key_exists('VERSION', $this->task_args)) {
             $goto_version = (int) $this->task_args['VERSION'];
         } else {
             //get the highest file version
             $goto_version = Ruckusing_VersionUtil::get_highest_migration(RUCKUSING_MIGRATION_DIR);
         }
         if ($db_version == $goto_version) {
             //nothing to do
             echo "\tNo migrations to run. DB is already at the current version ({$db_version}).\n";
         } else {
             if ($db_version > $goto_version) {
                 //GOING DOWN
                 $output = $this->migrate_down($goto_version, $db_version);
             } else {
                 if ($db_version < $goto_version) {
                     //GOING UP
                     $output = $this->migrate_up($db_version, $goto_version);
                 }
             }
         }
         if (!empty($output)) {
             echo $output . "\n\n";
         }
     } catch (Ruckusing_MissingSchemaInfoTableException $ex) {
         echo "\tSchema info table does not exist. I tried creating it but failed. Check permissions.";
     } catch (Ruckusing_MissingMigrationDirException $ex) {
         echo "\tMigration directory does not exist: " . RUCKUSING_MIGRATION_DIR;
     } catch (Ruckusing_Exception $ex) {
         die("\n\n" . $ex->getMessage() . "\n\n");
     }
     echo "\n\nFinished: " . date('Y-m-d g:ia T') . "\n\n";
 }
Пример #3
0
 public function test_get_highest_migration()
 {
     $this->assertEquals(3, Ruckusing_VersionUtil::get_highest_migration(RUCKUSING_MIGRATION_DIR));
 }