public function new_migration($name, $table = null) { if (is_array($name)) { $name = $name[0]; } $migrate = new WXMigrate(); $migrate->increase_version_latest(); $version = $migrate->get_version_latest(); $class = WXInflections::camelize($name, true); $this->final_output .= $this->start_php_file($class, "WXMigrate"); if ($table) { $this->final_output .= $this->add_function("up", sprintf(' \\$this->create_table(\\"%s\\");', $table) . "\n"); $this->final_output .= $this->add_function("down", sprintf(' \\$this->drop_table(\\"%s\\");', $table) . "\n"); } else { $this->final_output .= $this->add_function("up"); $this->final_output .= $this->add_function("down"); } $file = str_pad($version, 3, "0", STR_PAD_LEFT) . "_" . WXInflections::underscore($class); $res = $this->write_to_file(APP_DIR . "db/migrate/" . $file . ".php"); if (!$res) { $this->add_perm_error("app/db/migrate/" . $file . ".php"); return false; } $this->add_stdout("Created migration file at app/db/migrate/" . $file . ".php"); }
private function migrate_up(WXMigrate $class, $version) { $this->output("...updating with version " . $version . "\n"); $class->up(); $this->set_version($version); return true; }
/** * Join tables are automatically created, this little method handles it. * * @return void * @param $join **/ protected function initialise_has_many($join, $rel) { $migration = new WXMigrate(true); $migration->create_column($this->table . "_id", "integer"); $migration->create_column($rel . "_id", "integer"); $migration->create_column("order", "integer", 8, false, "0"); $migration->create_table($join, false); }
public function migrate($argv) { if (isset($argv[1]) && $argv[1] == "test" || $argv[1] == "production") { define("ENV", $argv[1]); unset($argv[1]); } elseif (isset($argv[1]) && $argv[1] == "directory" && isset($argv[2])) { $this->app_setup(); $migrate = new WXMigrate(true); $direction = "up"; if (isset($argv[3])) { $direction = "down"; } $result = $migrate->version_less_migrate($argv[2], $direction, true); exit($result . "\n"); } $this->app_setup(); $dbdir = WAX_ROOT . 'app/db/migrate/'; if (!is_dir($dbdir)) { $command = "mkdir -p {$dbdir}"; system($command); } $version = false; if (isset($argv[1])) { $version = $argv[1]; } $migrate = new WXMigrate(); if ($version == 'version') { $this->add_output("Now at version " . $migrate->get_version()); return false; } if ($version == 'clean') { $result = $migrate->migrate_revert($dbdir); $this->add_output("Database reset to version " . $result); return false; } $result = $migrate->migrate($dbdir, $version); if ($result === false) { $this->add_output("No Files to migrate"); return false; } $this->add_output("-------------------"); $this->add_output("Successfully migrated to version " . $result); $this->add_output("-------------------"); }