/** * Execute a migration against the specified Environment. * * @param string $name Environment Name * @param MigrationInterface $migration Migration * @param string $direction Direction * @return void */ public function executeMigration($name, MigrationInterface $migration, $direction = MigrationInterface::UP) { $this->getOutput()->writeln(''); $this->getOutput()->writeln(' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . ($direction == 'up' ? 'migrating' : 'reverting') . '</comment>'); // Execute the migration and log the time elapsed. $start = microtime(true); $this->getEnvironment($name)->executeMigration($migration, $direction); $end = microtime(true); $this->getOutput()->writeln(' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . ($direction == 'up' ? 'migrated' : 'reverted') . ' ' . sprintf('%.4fs', $end - $start) . '</comment>'); }
/** * {@inheritdoc} */ public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime) { if (strcasecmp($direction, MigrationInterface::UP) === 0) { // up $sql = sprintf('INSERT INTO %s (' . 'version, migration_name, start_time, end_time, breakpoint' . ') VALUES (' . '\'%s\',' . '\'%s\',' . '\'%s\',' . '\'%s\',' . '0' . ');', $this->getSchemaTableName(), $migration->getVersion(), substr($migration->getName(), 0, 100), $startTime, $endTime); $this->query($sql); } else { // down $sql = sprintf("DELETE FROM %s WHERE version = '%s'", $this->getSchemaTableName(), $migration->getVersion()); $this->query($sql); } return $this; }
/** * {@inheritdoc} */ public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime) { if (strcasecmp($direction, MigrationInterface::UP) === 0) { // up $sql = sprintf("INSERT INTO %s ([version], [migration_name], [start_time], [end_time], [breakpoint]) VALUES ('%s', '%s', '%s', '%s', 0);", $this->getSchemaTableName(), $migration->getVersion(), substr($migration->getName(), 0, 100), $startTime, $endTime); $this->query($sql); } else { // down $sql = sprintf("DELETE FROM %s WHERE [version] = '%s'", $this->getSchemaTableName(), $migration->getVersion()); $this->query($sql); } return $this; }
/** * {@inheritdoc} */ public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime) { if (strcasecmp($direction, MigrationInterface::UP) === 0) { // up $sql = sprintf("INSERT INTO %s (%s, %s, %s, %s, %s) VALUES ('%s', '%s', '%s', '%s', %s);", $this->getSchemaTableName(), $this->quoteColumnName('version'), $this->quoteColumnName('migration_name'), $this->quoteColumnName('start_time'), $this->quoteColumnName('end_time'), $this->quoteColumnName('breakpoint'), $migration->getVersion(), substr($migration->getName(), 0, 100), $startTime, $endTime, $this->castToBool(false)); $this->query($sql); } else { // down $sql = sprintf("DELETE FROM %s WHERE %s = '%s'", $this->getSchemaTableName(), $this->quoteColumnName('version'), $migration->getVersion()); $this->query($sql); } return $this; }