/** * Create migration with description */ public function testCreateVersionWithCustomName() { $versionName = '003'; $versionDescription = 'My super migration'; $version = new Version(new Configuration($this->getSqliteConnection()), $versionName, 'Doctrine\\DBAL\\Migrations\\Tests\\Stub\\VersionDummyDescription'); $this->assertEquals($versionName, $version->getVersion()); $this->assertEquals($versionDescription, $version->getMigration()->getDescription()); }
/** * Check if we should execute a migration for a given direction and target * migration version. * * @param string $direction The direction we are migrating. * @param Version $version The Version instance to check. * @param string $to The version we are migrating to. * @param array $migrated Migrated versions array. * * @return boolean */ private function shouldExecuteMigration($direction, Version $version, $to, $migrated) { if ($direction === 'down') { if (!in_array($version->getVersion(), $migrated)) { return false; } return $version->getVersion() > $to; } if ($direction === 'up') { if (in_array($version->getVersion(), $migrated)) { return false; } return $version->getVersion() <= $to; } }
/** * Check if we should execute a migration for a given direction and target * migration version. * * @param string $direction The direction we are migrating. * @param Version $version The Version instance to check. * @param string $to The version we are migrating to. * @param array $migrated Migrated versions array. * * @return boolean */ private function shouldExecuteMigration($direction, Version $version, $to, $migrated) { if ($direction === Version::DIRECTION_DOWN) { if (!in_array($version->getVersion(), $migrated)) { return false; } return $version->getVersion() > $to; } if ($direction === Version::DIRECTION_UP) { if (in_array($version->getVersion(), $migrated)) { return false; } return $version->getVersion() <= $to; } }
/** * Create migration with custom name */ public function testCreateVersionWithCustomName() { $versionName = 'CustomVersionName'; $version = new Version(new Configuration($this->getSqliteConnection()), '003', 'Doctrine\\DBAL\\Migrations\\Tests\\VersionTest_MigrationCustom'); $this->assertEquals($versionName, $version->getVersion()); }
/** * Register a single migration version to be executed by a AbstractMigration * class. * * @param string $version The version of the migration in the format YYYYMMDDHHMMSS. * @param string $class The migration class to execute for the version. */ public function registerMigration($version, $class) { $version = (string) $version; $class = (string) $class; if (isset($this->migrations[$version])) { throw MigrationException::duplicateMigrationVersion($version, get_class($this->migrations[$version])); } $version = new Version($this, $version, $class); $this->migrations[$version->getVersion()] = $version; ksort($this->migrations); return $version; }