diff --git a/.travis.yml b/.travis.yml index 7f83832..1f1772c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,5 @@ install: - composer install script: - - phpunit tests/SqliteCommandTest.php + - phpunit tests/SqliteDatabaseTest.php diff --git a/README.md b/README.md index 746f1ca..344443d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![SensioLabsInsight](https://insight.sensiolabs.com/projects/571cb412-7018-4938-a4e5-0f9ce44956d7/mini.png)](https://insight.sensiolabs.com/projects/571cb412-7018-4938-a4e5-0f9ce44956d7) [![Build Status](https://travis-ci.org/byjg/migration.svg?branch=master)](https://travis-ci.org/byjg/migration) -A micro framework in PHP for managing a set of database migrations using pure Sql. +Simple library in PHP for database version control. Supports Sqlite, MySql, Sql Server and Postgres. Database Migration is a set of commands for upgrade or downgrade a database. This library uses only SQL commands. @@ -66,6 +66,25 @@ For example: 00002.sql is the script for move the database from version '1' to ' For example: 00001.sql is the script for move the database from version '2' to '1'. The "down" folder is optional. +### Multi Development environment + +If you work with multiple developers and multiple branches it is to difficult to determine what is the next number. + +In that case you have the suffix "-dev" after the version number. + +See the scenario: + +- Developer 1 create a branch and the most recent version in e.g. 42. +- Developer 2 create a branch at the same time and have the same database version number. + +In both case the developers will create a file called 43-dev.sql. Both developers will migrate UP and DOWN with +no problem and your local version will be 43. + +But developer 1 merged your changes and created a final version 43.sql (`git mv 43-dev.sql 43.sql`). If the developer 2 +update your local branch he will have a file 43.sql (from dev 1) and your file 43-dev.sql. +If he is try to migrate UP or DOWN +the migration script will down and alert him there a TWO versions 43. In that case, developer 2 will have to update your +file do 44-dev.sql and continue to work until merge your changes and generate a final version. ## Running in the command line @@ -76,9 +95,12 @@ Usage: command [options] [arguments] Available commands: + create Create the directory structure FROM a pre-existing database + install Install or upgrade the migrate version in a existing database down Migrate down the database version. reset Create a fresh new database up Migrate Up the database version + version Get the current database version Arguments: connection The connection string. Ex. mysql://root:password@server/database [default: false] @@ -91,7 +113,7 @@ Example: migrate down --up-to=3 --path=/somepath mysql://root:password@server/database ``` -## Suportted databases: +## Supported databases: * Sqlite * Mysql / MariaDB @@ -101,7 +123,7 @@ Example: ## Installing Globally ```bash -composer global require 'byjg/migration=1.1.*' +composer global require 'byjg/migration=2.0.*' sudo ln -s $HOME/.composer/vendor/bin/migrate /usr/local/bin ``` @@ -112,8 +134,8 @@ This library has integrated tests and need to be setup for each database you wan Basiclly you have the follow tests: ``` -phpunit tests/SqliteCommandTest.php -phpunit tests/MysqlCommandTest.php -phpunit tests/PostgresCommandTest.php -phpunit tests/SqlServerCommandTest.php +phpunit tests/SqliteDatabaseTest.php +phpunit tests/MysqlDatabaseTest.php +phpunit tests/PostgresDatabaseTest.php +phpunit tests/SqlServerDatabaseTest.php ``` \ No newline at end of file diff --git a/composer.json b/composer.json index ae07d2f..2656caa 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "byjg/migration", - "description": "A micro framework in PHP for managing a set of database migrations using pure Sql.", + "description": "Simple library in PHP for database version control. Supports Sqlite, MySql, Sql Server and Postgres.", "authors": [ { "name": "jg", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 32c9fc6..40fcae7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -22,7 +22,7 @@ and open the template in the editor. - ./tests/SqliteCommandTest.php + ./tests/SqliteDatabaseTest.php diff --git a/scripts/migrate b/scripts/migrate index 371836e..a66ff19 100755 --- a/scripts/migrate +++ b/scripts/migrate @@ -13,10 +13,12 @@ require_once($autoload); use Symfony\Component\Console\Application; -$application = new Application('Migrate Script by JG', '1.1.1'); +$application = new Application('Migrate Script by JG', '2.0.0'); $application->add(new \ByJG\DbMigration\Console\ResetCommand()); $application->add(new \ByJG\DbMigration\Console\UpCommand()); $application->add(new \ByJG\DbMigration\Console\DownCommand()); $application->add(new \ByJG\DbMigration\Console\CreateCommand()); $application->add(new \ByJG\DbMigration\Console\DatabaseVersionCommand()); +$application->add(new \ByJG\DbMigration\Console\InstallCommand()); +$application->add(new \ByJG\DbMigration\Console\UpdateCommand()); $application->run(); diff --git a/src/Commands/AbstractCommand.php b/src/Commands/AbstractCommand.php deleted file mode 100644 index 1a02759..0000000 --- a/src/Commands/AbstractCommand.php +++ /dev/null @@ -1,54 +0,0 @@ -dbDriver = $dbDriver; - } - - /** - * @return DbDriverInterface - */ - public function getDbDriver() - { - return $this->dbDriver; - } - - public function getVersion() - { - try { - return $this->getDbDriver()->getScalar('SELECT version FROM migration_version'); - } catch (\Exception $ex) { - throw new \Exception('This database does not have a migration version. Please use "migrate reset" to create one.'); - } - } - - public function setVersion($version) - { - $this->getDbDriver()->execute('UPDATE migration_version SET version = :version', ['version' => $version]); - } - - protected function checkExistsVersion() - { - // Get the version to check if exists - $version = $this->getVersion(); - if (empty($version)) { - $this->getDbDriver()->execute('insert into migration_version values(0)'); - } - } -} diff --git a/src/Console/ConsoleCommand.php b/src/Console/ConsoleCommand.php index 1b88295..740d557 100644 --- a/src/Console/ConsoleCommand.php +++ b/src/Console/ConsoleCommand.php @@ -2,7 +2,6 @@ namespace ByJG\DbMigration\Console; -use ByJG\AnyDataset\ConnectionManagement; use ByJG\DbMigration\Migration; use ByJG\Util\Uri; use Symfony\Component\Console\Command\Command; @@ -89,5 +88,18 @@ protected function execute(InputInterface $input, OutputInterface $output) } } + /** + * @param \Exception|\Error $ex + * @param \Symfony\Component\Console\Output\OutputInterface $output + */ + protected function handleError($ex, OutputInterface $output) + { + $output->writeln('-- Error migrating tables --'); + if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { + $output->writeln(get_class($ex)); + $output->writeln($ex->getMessage()); + } + } + } diff --git a/src/Console/DatabaseVersionCommand.php b/src/Console/DatabaseVersionCommand.php index a1d8830..74c14c9 100644 --- a/src/Console/DatabaseVersionCommand.php +++ b/src/Console/DatabaseVersionCommand.php @@ -25,6 +25,12 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); - $output->writeln('version: ' . $this->migration->getCurrentVersion()); + try { + $versionInfo = $this->migration->getCurrentVersion(); + $output->writeln('version: ' . $versionInfo['version']); + $output->writeln('status.: ' . $versionInfo['status']); + } catch (\Exception $ex) { + $this->handleError($ex, $output); + } } } diff --git a/src/Console/DownCommand.php b/src/Console/DownCommand.php index 1f924b0..0dbbead 100644 --- a/src/Console/DownCommand.php +++ b/src/Console/DownCommand.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; class DownCommand extends ConsoleCommand { @@ -24,8 +25,27 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - parent::execute($input, $output); - $this->migration->down($this->upTo); + try { + $versionInfo = $this->migration->getCurrentVersion(); + if (strpos($versionInfo['status'], 'partial') !== false) { + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion( + 'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N)', + false + ); + + if (!$helper->ask($input, $output, $question)) { + $output->writeln('Aborted.'); + + return; + } + } + + parent::execute($input, $output); + $this->migration->down($this->upTo, true); + } catch (\Exception $ex) { + $this->handleError($ex, $output); + } } } diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php new file mode 100644 index 0000000..be9159d --- /dev/null +++ b/src/Console/InstallCommand.php @@ -0,0 +1,51 @@ +setName('install') + ->setDescription('Install or upgrade the migrate version in a existing database'); + + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + try { + parent::execute($input, $output); + + $action = 'Database is already versioned. '; + try { + $this->migration->getCurrentVersion(); + } catch (DatabaseNotVersionedException $ex) { + $action = 'Created the version table'; + $this->migration->createVersion(); + } catch (OldVersionSchemaException $ex) { + $action = 'Updated the version table'; + $this->migration->updateTableVersion(); + } + + $version = $this->migration->getCurrentVersion(); + $output->writeln($action); + $output->writeln('current version: ' . $version['version']); + $output->writeln('current status.: ' . $version['status']); + } catch (\Exception $ex) { + $this->handleError($ex, $output); + } + } +} diff --git a/src/Console/ResetCommand.php b/src/Console/ResetCommand.php index 9ceea01..cbacae2 100644 --- a/src/Console/ResetCommand.php +++ b/src/Console/ResetCommand.php @@ -25,17 +25,23 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $helper = $this->getHelper('question'); - $question = new ConfirmationQuestion('This will ERASE all of data in your data. Continue with this action? (y/N) ', false); - - if (!$helper->ask($input, $output, $question)) { - $output->writeln('Aborted.'); - return; + try { + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion('This will ERASE all of data in your data. Continue with this action? (y/N) ', + false); + + if (!$helper->ask($input, $output, $question)) { + $output->writeln('Aborted.'); + + return; + } + + parent::execute($input, $output); + $this->migration->prepareEnvironment(); + $this->migration->reset($this->upTo); + } catch (\Exception $ex) { + $this->handleError($ex, $output); } - - parent::execute($input, $output); - $this->migration->prepareEnvironment(); - $this->migration->reset($this->upTo); } } diff --git a/src/Console/UpCommand.php b/src/Console/UpCommand.php index 0dcad72..7a8a0a4 100644 --- a/src/Console/UpCommand.php +++ b/src/Console/UpCommand.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; class UpCommand extends ConsoleCommand { @@ -24,7 +25,26 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - parent::execute($input, $output); - $this->migration->up($this->upTo); + try { + $versionInfo = $this->migration->getCurrentVersion(); + if (strpos($versionInfo['status'], 'partial') !== false) { + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion( + 'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N) ', + false + ); + + if (!$helper->ask($input, $output, $question)) { + $output->writeln('Aborted.'); + + return; + } + } + + parent::execute($input, $output); + $this->migration->up($this->upTo, true); + } catch (\Exception $ex) { + $this->handleError($ex, $output); + } } } diff --git a/src/Console/UpdateCommand.php b/src/Console/UpdateCommand.php new file mode 100644 index 0000000..a6c8f8c --- /dev/null +++ b/src/Console/UpdateCommand.php @@ -0,0 +1,52 @@ +setName('update') + ->setDescription('Migrate Up or Down the database version based on the current database version and the ' . + 'migration scripts available' + ); + + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + try { + $versionInfo = $this->migration->getCurrentVersion(); + if (strpos($versionInfo['status'], 'partial') !== false) { + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion( + 'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N) ', + false + ); + + if (!$helper->ask($input, $output, $question)) { + $output->writeln('Aborted.'); + + return; + } + } + + parent::execute($input, $output); + $this->migration->update($this->upTo, true); + } catch (\Exception $ex) { + $this->handleError($ex, $output); + } + } +} diff --git a/src/Database/AbstractDatabase.php b/src/Database/AbstractDatabase.php new file mode 100644 index 0000000..5f8d415 --- /dev/null +++ b/src/Database/AbstractDatabase.php @@ -0,0 +1,79 @@ +dbDriver = $dbDriver; + } + + /** + * @return DbDriverInterface + */ + public function getDbDriver() + { + return $this->dbDriver; + } + + public function getVersion() + { + $result = []; + try { + $result['version'] = $this->getDbDriver()->getScalar('SELECT version FROM migration_version'); + } catch (\Exception $ex) { + throw new DatabaseNotVersionedException('This database does not have a migration version. Please use "migrate reset" or "migrate install" to create one.'); + } + + try { + $result['status'] = $this->getDbDriver()->getScalar('SELECT status FROM migration_version'); + } catch (\Exception $ex) { + throw new OldVersionSchemaException('This database does not have a migration version. Please use "migrate install" for update it.'); + } + + return $result; + } + + public function setVersion($version, $status) + { + $this->getDbDriver()->execute( + 'UPDATE migration_version SET version = :version, status = :status', + [ + 'version' => $version, + 'status' => $status + ] + ); + } + + protected function checkExistsVersion() + { + // Get the version to check if exists + $versionInfo = $this->getVersion(); + if (empty($versionInfo['version'])) { + $this->getDbDriver()->execute("insert into migration_version values(0, 'unknow')"); + } + } + + public function updateVersionTable() + { + $currentVersion = $this->getDbDriver()->getScalar('select version from migration_version'); + $this->getDbDriver()->execute('drop table migration_version'); + $this->createVersion(); + $this->setVersion($currentVersion, 'unknow'); + } +} diff --git a/src/Commands/CommandInterface.php b/src/Database/DatabaseInterface.php similarity index 65% rename from src/Commands/CommandInterface.php rename to src/Database/DatabaseInterface.php index 40c3771..1b6503b 100644 --- a/src/Commands/CommandInterface.php +++ b/src/Database/DatabaseInterface.php @@ -1,10 +1,10 @@ getDbDriver()->getUri()->getPath()); $table = 'migration_version'; - $createTable = 'CREATE TABLE migration_version (version int)'; + $createTable = 'CREATE TABLE migration_version (version int, status varchar(20))'; $this->createTableIfNotExists($database, $table, $createTable); $this->checkExistsVersion(); } diff --git a/src/Commands/MysqlCommand.php b/src/Database/MysqlDatabase.php similarity index 89% rename from src/Commands/MysqlCommand.php rename to src/Database/MysqlDatabase.php index 5ed9e27..d5c06b8 100644 --- a/src/Commands/MysqlCommand.php +++ b/src/Database/MysqlDatabase.php @@ -1,11 +1,11 @@ getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int)'); + $this->getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int, status varchar(20))'); $this->checkExistsVersion(); } diff --git a/src/Commands/PgsqlCommand.php b/src/Database/PgsqlDatabase.php similarity index 89% rename from src/Commands/PgsqlCommand.php rename to src/Database/PgsqlDatabase.php index 460f76c..ef372b9 100644 --- a/src/Commands/PgsqlCommand.php +++ b/src/Database/PgsqlDatabase.php @@ -1,11 +1,11 @@ withPath('/')->__toString()); } + /** + * @param \ByJG\AnyDataset\DbDriverInterface $dbDriver + * @param $database + */ protected static function createDatabaseIfNotExists($dbDriver, $database) { $currentDbName = $dbDriver->getScalar( @@ -53,7 +57,7 @@ public function dropDatabase() public function createVersion() { - $this->getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int)'); + $this->getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int, status varchar(20))'); $this->checkExistsVersion(); } diff --git a/src/Commands/SqliteCommand.php b/src/Database/SqliteDatabase.php similarity index 87% rename from src/Commands/SqliteCommand.php rename to src/Database/SqliteDatabase.php index f05ac7b..84ff6c7 100644 --- a/src/Commands/SqliteCommand.php +++ b/src/Database/SqliteDatabase.php @@ -1,10 +1,10 @@ getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int)'); + $this->getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int, status varchar(20))'); $this->checkExistsVersion(); } diff --git a/src/Exception/DatabaseIsIncompleteException.php b/src/Exception/DatabaseIsIncompleteException.php new file mode 100644 index 0000000..fbe6df1 --- /dev/null +++ b/src/Exception/DatabaseIsIncompleteException.php @@ -0,0 +1,14 @@ +_dbCommand)) { - $class = $this->getCommandClassName(); + $class = $this->getDatabaseClassName(); $this->_dbCommand = new $class($this->getDbDriver()); } return $this->_dbCommand; } - protected function getCommandClassName() + protected function getDatabaseClassName() { - return "\\ByJG\\DbMigration\\Commands\\" . ucfirst($this->uri->getScheme()) . "Command"; + return "\\ByJG\\DbMigration\\Database\\" . ucfirst($this->uri->getScheme()) . "Database"; } /** @@ -97,18 +98,35 @@ public function getBaseSql() */ public function getMigrationSql($version, $increment) { - $result = glob( - $this->_folder + // I could use the GLOB_BRACE but it is not supported on ALPINE distros. + // So, I have to call multiple times to simulate the braces. + + if (intval($version) != $version) { + throw new \InvalidArgumentException("Version '$version' should be a integer number"); + } + $version = intval($version); + + $filePattern = $this->_folder . "/migrations" . "/" . ($increment < 0 ? "down" : "up") - . "/*$version.sql" + . "/*%s.sql"; + + $result = array_merge( + glob(sprintf($filePattern, "$version")), + glob(sprintf($filePattern, "$version-dev")) ); + // Valid values are 0 or 1 + if (count($result) > 1) { + throw new \InvalidArgumentException("You have two files with the same version $version number"); + } + foreach ($result as $file) { - if (intval(basename($file)) == $version) { + if (intval(basename($file)) === $version) { return $file; } } + return null; } /** @@ -116,7 +134,7 @@ public function getMigrationSql($version, $increment) */ public function prepareEnvironment() { - $class = $this->getCommandClassName(); + $class = $this->getDatabaseClassName(); $class::prepareEnvironment($this->uri); } @@ -133,11 +151,22 @@ public function reset($upVersion = null) } $this->getDbCommand()->dropDatabase(); $this->getDbCommand()->createDatabase(); - $this->getDbCommand()->executeSql(file_get_contents($this->getBaseSql())); $this->getDbCommand()->createVersion(); + $this->getDbCommand()->executeSql(file_get_contents($this->getBaseSql())); + $this->getDbCommand()->setVersion(0, 'complete'); $this->up($upVersion); } + public function createVersion() + { + $this->getDbCommand()->createVersion(); + } + + public function updateTableVersion() + { + $this->getDbCommand()->updateVersionTable(); + } + /** * Get the current database version * @@ -145,7 +174,7 @@ public function reset($upVersion = null) */ public function getCurrentVersion() { - return intval($this->getDbCommand()->getVersion()); + return $this->getDbCommand()->getVersion(); } /** @@ -157,12 +186,16 @@ public function getCurrentVersion() protected function canContinue($currentVersion, $upVersion, $increment) { $existsUpVersion = ($upVersion !== null); - $compareVersion = strcmp( - str_pad($currentVersion, 5, '0', STR_PAD_LEFT), - str_pad($upVersion, 5, '0', STR_PAD_LEFT) - ) == $increment; + $compareVersion = + intval($currentVersion) < intval($upVersion) + ? -1 + : ( + intval($currentVersion) > intval($upVersion) + ? 1 + : 0 + ); - return !($existsUpVersion && $compareVersion); + return !($existsUpVersion && ($compareVersion === intval($increment))); } /** @@ -170,11 +203,18 @@ protected function canContinue($currentVersion, $upVersion, $increment) * * @param int $upVersion * @param int $increment Can accept 1 for UP or -1 for down + * @param bool $force + * @throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException */ - protected function migrate($upVersion, $increment) + protected function migrate($upVersion, $increment, $force) { - $currentVersion = $this->getCurrentVersion() + $increment; - + $versionInfo = $this->getCurrentVersion(); + $currentVersion = intval($versionInfo['version']) + $increment; + + if (strpos($versionInfo['status'], 'partial') !== false && !$force) { + throw new DatabaseIsIncompleteException('Database was not fully updated. Use --force for migrate.'); + } + while ($this->canContinue($currentVersion, $upVersion, $increment) && file_exists($file = $this->getMigrationSql($currentVersion, $increment)) ) { @@ -182,8 +222,9 @@ protected function migrate($upVersion, $increment) call_user_func_array($this->_callableProgress, ['migrate', $currentVersion]); } + $this->getDbCommand()->setVersion($currentVersion, 'partial ' . ($increment>0 ? 'up' : 'down')); $this->getDbCommand()->executeSql(file_get_contents($file)); - $this->getDbCommand()->setVersion($currentVersion); + $this->getDbCommand()->setVersion($currentVersion, 'complete'); $currentVersion = $currentVersion + $increment; } } @@ -192,20 +233,39 @@ protected function migrate($upVersion, $increment) * Run all scripts to up the database version from current up to latest version or the specified version. * * @param int $upVersion + * @param bool $force */ - public function up($upVersion = null) + public function up($upVersion = null, $force = false) { - $this->migrate($upVersion, 1); + $this->migrate($upVersion, 1, $force); + } + + /** + * Run all scripts to up or down the database version from current up to latest version or the specified version. + * + * @param int $upVersion + * @param bool $force + */ + public function update($upVersion = null, $force = false) + { + $versionInfo = $this->getCurrentVersion(); + $version = intval($versionInfo['version']); + $increment = 1; + if ($upVersion !== null && $upVersion < $version) { + $increment = -1; + } + $this->migrate($upVersion, $increment, $force); } /** * Run all scripts to down the database version from current version up to the specified version. * * @param int $upVersion + * @param bool $force */ - public function down($upVersion) + public function down($upVersion, $force = false) { - $this->migrate($upVersion, -1); + $this->migrate($upVersion, -1, $force); } public function addCallbackProgress(Callable $callable) diff --git a/tests/BaseCommand.php b/tests/BaseDatabase.php similarity index 89% rename from tests/BaseCommand.php rename to tests/BaseDatabase.php index 434b96a..63136ec 100644 --- a/tests/BaseCommand.php +++ b/tests/BaseDatabase.php @@ -5,7 +5,7 @@ class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase'); } -abstract class BaseCommand extends \PHPUnit\Framework\TestCase +abstract class BaseDatabase extends \PHPUnit\Framework\TestCase { protected $uri = null; @@ -84,6 +84,8 @@ protected function assertVersion0() { $version = $this->migrate->getDbDriver()->getScalar('select version from migration_version'); $this->assertEquals(0, $version); + $status = $this->migrate->getDbDriver()->getScalar('select status from migration_version'); + $this->assertEquals('complete', $status); $iterator = $this->migrate->getDbDriver()->getIterator('select * from users'); @@ -114,6 +116,8 @@ protected function assertVersion1() { $version = $this->migrate->getDbDriver()->getScalar('select version from migration_version'); $this->assertEquals(1, $version); + $status = $this->migrate->getDbDriver()->getScalar('select status from migration_version'); + $this->assertEquals('complete', $status); $iterator = $this->migrate->getDbDriver()->getIterator('select * from users'); @@ -144,6 +148,8 @@ protected function assertVersion2() { $version = $this->migrate->getDbDriver()->getScalar('select version from migration_version'); $this->assertEquals(2, $version); + $status = $this->migrate->getDbDriver()->getScalar('select status from migration_version'); + $this->assertEquals('complete', $status); $iterator = $this->migrate->getDbDriver()->getIterator('select * from users'); diff --git a/tests/MysqlCommandTest.php b/tests/MysqlDatabaseTest.php similarity index 82% rename from tests/MysqlCommandTest.php rename to tests/MysqlDatabaseTest.php index 765d0aa..2b11247 100644 --- a/tests/MysqlCommandTest.php +++ b/tests/MysqlDatabaseTest.php @@ -1,8 +1,8 @@