public function test_class_from_migration_file_name() { $klass = '001_CreateUsers.php'; $this->assertEquals('CreateUsers', NamingUtil::class_from_migration_file($klass)); $klass = '120_AddIndexToPeopleTable.php'; $this->assertEquals('AddIndexToPeopleTable', NamingUtil::class_from_migration_file($klass)); }
private function run_migrations($migrations, $target_method, $destination) { $last_version = -1; foreach ($migrations as $file) { $full_path = MIGRATION_DIR . '/' . $file['file']; if (is_file($full_path) && is_readable($full_path)) { require_once $full_path; $klass = NamingUtil::class_from_migration_file($file['file']); $obj = new $klass(); $refl = new ReflectionObject($obj); if ($refl->hasMethod($target_method)) { $obj->set_adapter($this->adapter); $start = $this->start_timer(); try { //start transaction $this->adapter->start_transaction(); $result = $obj->{$target_method}(); //successfully ran migration, update our version and commit $version = $this->resolve_versions($destination, $file['version'], $target_method); $this->adapter->set_current_version($version); $this->adapter->commit_transaction(); } catch (Exception $e) { $this->adapter->rollback_transaction(); //wrap the caught exception in our own $ex = new Exception(sprintf("%s - %s", $file['class'], $e->getMessage())); throw $ex; } $end = $this->end_timer(); $diff = $this->diff_timer($start, $end); printf("========= %s ======== (%.2f)\n", $file['class'], $diff); $last_version = $file['version']; $exec = true; } else { trigger_error("ERROR: {$klass} does not have a '{$target_method}' method defined!"); } } //is_file } //foreach //update the schema info $result = array('last_version' => $last_version); return $result; }