public function testMigrationByDiff() { $this->conn->query('DROP TABLE IF EXISTS users'); $this->conn->query('DROP TABLE IF EXISTS test'); $this->conn->query('CREATE TABLE users (account VARCHAR(128) UNIQUE)'); if (!file_exists('tests/migrations_testing')) { mkdir('tests/migrations_testing'); } $generator = new MigrationGenerator(Console::getInstance()->getLogger(), 'tests/migrations_testing'); ok(class_exists('TestApp\\Model\\UserSchema', true)); $finder = new SchemaFinder(); $finder->find(); list($class, $path) = $generator->generateWithDiff('DiffMigration', $this->getDriverType(), ["users" => new TestApp\Model\UserSchema()], '20120101'); require_once $path; ok($class::getId()); /* $userSchema = new TestApp\Model\UserSchema; $column = $userSchema->getColumn('account'); */ // run migration $runner = new MigrationRunner($this->logger, $this->getDriverType()); $runner->resetMigrationId($this->conn, $this->queryDriver); $runner->load('tests/migrations_testing'); // XXX: PHPUnit can't run this test in separated unit test since // there is a bug of serializing the global array, this assertion will get 5 instead of the expected 1. $scripts = $runner->loadMigrationScripts(); $this->assertNotEmpty($scripts); // $this->assertCount(1, $scripts); // $this->expectOutputRegex('#DiffMigration_1325347200#'); $runner->runUpgrade($this->conn, $this->queryDriver, [$class]); # echo file_get_contents($path); unlink($path); $this->conn->query('DROP TABLE IF EXISTS users'); }
public function testRunner() { $connm = LazyRecord\ConnectionManager::getInstance(); $connm->addDataSource('default', array('dsn' => 'sqlite::memory:')); $runner = new LazyRecord\Migration\MigrationRunner('default'); $runner->load('tests/migrations'); $runner->runUpgradeAutomatically(); }
public function execute() { $dsId = $this->getCurrentDataSourceId(); $runner = new MigrationRunner($dsId); $runner->load($this->options->{'script-dir'} ?: 'db/migrations'); $this->logger->info('Running migration scripts to downgrade...'); $runner->runDowngrade(); $this->logger->info('Done.'); }
public function execute() { $dsId = $this->getCurrentDataSourceId(); $runner = new MigrationRunner($dsId); $runner->load('db/migrations'); $scripts = $runner->getUpgradeScripts($dsId); $count = count($scripts); $this->logger->info("Found " . $count . ($count > 1 ? ' migration scripts' : ' migration script') . ' to be executed.'); foreach ($scripts as $script) { $this->logger->info('- ' . $script, 1); } }
public function execute() { $dsId = $this->getCurrentDataSourceId(); $connectionManager = ConnectionManager::getInstance(); $conn = $connectionManager->getConnection($dsId); $driver = $connectionManager->getQueryDriver($dsId); $runner = new MigrationRunner($this->logger, $dsId); $runner->load($this->options->{'script-dir'} ?: 'db/migrations'); $scripts = $runner->getUpgradeScripts($conn, $driver); $count = count($scripts); $this->logger->info('Found ' . $count . ($count > 1 ? ' migration scripts' : ' migration script') . ' to be executed.'); foreach ($scripts as $script) { $this->logger->info('- ' . $script, 1); } }
public function testMigrationByDiff() { $connectionManager = ConnectionManager::getInstance(); $connectionManager->addDataSource('default', array('driver' => 'mysql', 'dsn' => @$_ENV['DB_MYSQL_DSN'], 'user' => @$_ENV['DB_MYSQL_USER'], 'pass' => @$_ENV['DB_MYSQL_PASS'])); $pdo = $connectionManager->getConnection('default'); $pdo->query('DROP TABLE IF EXISTS users'); $pdo->query('DROP TABLE IF EXISTS test'); $pdo->query('CREATE TABLE users (account VARCHAR(128) UNIQUE)'); if (!file_exists('tests/migrations_testing')) { mkdir('tests/migrations_testing'); } $generator = new MigrationGenerator(Console::getInstance()->getLogger(), 'tests/migrations_testing'); ok(class_exists('TestApp\\Model\\UserSchema', true)); $finder = new SchemaFinder(); $finder->find(); list($class, $path) = $generator->generateWithDiff('DiffMigration', 'default', [new TestApp\Model\UserSchema()], '20120101'); require_once $path; ok($class::getId()); /* $userSchema = new TestApp\Model\UserSchema; $column = $userSchema->getColumn('account'); */ /* */ // run migration $runner = new MigrationRunner('default'); $runner->resetMigrationId('default'); $runner->load('tests/migrations_testing'); // XXX: PHPUnit can't run this test in separated unit test since // there is a bug of serializing the global array, this assertion will get 5 instead of the expected 1. $scripts = $runner->getMigrationScripts(); $this->assertNotEmpty($scripts); // $this->assertCount(1, $scripts); // $this->expectOutputRegex('#DiffMigration_1325347200#'); $runner->runUpgrade([$class]); # echo file_get_contents($path); unlink($path); $pdo->query('DROP TABLE IF EXISTS users'); $connectionManager->removeDataSource('default'); $connectionManager->close('default'); }
public function execute() { $connection = $this->getCurrentConnection(); $driver = $this->getCurrentQueryDriver(); if ($this->options->backup) { if (!$driver instanceof PDOMySQLDriver) { $this->logger->error('backup is only supported for MySQL'); return false; } $this->logger->info('Backing up database...'); $backup = new MySQLBackup(); if ($dbname = $backup->incrementalBackup($connection)) { $this->logger->info("Backup at {$dbname}"); } } $dsId = $this->getCurrentDataSourceId(); $runner = new MigrationRunner($this->logger, $dsId); $runner->load($this->options->{'script-dir'} ?: 'db/migrations'); $this->logger->info("Performing downgrade over data source: {$dsId}..."); $runner->runDowngrade($connection, $driver); $this->logger->info('Done.'); }