From bc2b46bddba4b7379c78c383395fb780e1de0357 Mon Sep 17 00:00:00 2001 From: Alexandre GUIDET Date: Mon, 9 Mar 2015 15:47:25 +0100 Subject: [PATCH 01/16] [twgit] Init hotfix 'hotfix-3.4.2'. From 533599ba5ce252e4f794243ac7b22b57bed1a589 Mon Sep 17 00:00:00 2001 From: Alexandre GUIDET Date: Mon, 9 Mar 2015 16:04:32 +0100 Subject: [PATCH 02/16] error deal ok --- Migrate/Command/AbstractEnvCommand.php | 32 ++++++++++++++++-- tests/Command/UpDownCommandTest.php | 46 +++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/Migrate/Command/AbstractEnvCommand.php b/Migrate/Command/AbstractEnvCommand.php index fec017a..7c3db0d 100644 --- a/Migrate/Command/AbstractEnvCommand.php +++ b/Migrate/Command/AbstractEnvCommand.php @@ -11,6 +11,7 @@ use Migrate\Migration; use Migrate\Utils\ArrayUtil; +use SebastianBergmann\GlobalState\RuntimeException; use Symfony\Component\Config\FileLocator; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -204,8 +205,22 @@ public function removeFromChangelog(Migration $migration) */ public function executeUpMigration(Migration $migration) { - $this->getDb()->query($migration->getSqlUp()); + $this->getDb()->beginTransaction(); + $result = $this->getDb()->query($migration->getSqlUp()); + + if ($result === false) { + // error while executing the migration + $errorInfo = ""; + $errorInfos = $this->getDb()->errorInfo(); + foreach ($errorInfos as $line) { + $errorInfo .= "\n$line"; + } + $this->getDb()->rollBack(); + throw new \RuntimeException("migration error, some SQL may be wrong\n\nid: {$migration->getId()}\nfile: {$migration->getFile()}\n" . $errorInfo); + } + $this->saveToChangelog($migration); + $this->getDb()->commit(); } /** @@ -213,8 +228,21 @@ public function executeUpMigration(Migration $migration) */ public function executeDownMigration(Migration $migration) { - $this->getDb()->query($migration->getSqlDown()); + $this->getDb()->beginTransaction(); + $result = $this->getDb()->query($migration->getSqlDown()); + + if ($result === false) { + // error while executing the migration + $errorInfo = ""; + $errorInfos = $this->getDb()->errorInfo(); + foreach ($errorInfos as $line) { + $errorInfo .= "\n$line"; + } + $this->getDb()->rollBack(); + throw new \RuntimeException("migration error, some SQL may be wrong\n\nid: {$migration->getId()}\nfile: {$migration->getFile()}\n" . $errorInfo); + } $this->removeFromChangelog($migration); + $this->getDb()->commit(); } protected function filterMigrationsToExecute(InputInterface $input, OutputInterface $output) diff --git a/tests/Command/UpDownCommandTest.php b/tests/Command/UpDownCommandTest.php index 62d7649..82781e4 100644 --- a/tests/Command/UpDownCommandTest.php +++ b/tests/Command/UpDownCommandTest.php @@ -28,7 +28,7 @@ public function setUp() $this->initEnv(); $this->createMigration('0', "CREATE TABLE test (id INTEGER, thevalue TEXT);", "DROP TABLE test;"); - $this->createMigration('1', "INSERT INTO test VALUES (1, 'one');", "DELETE FROM test WHERE id = 1;"); + $this->createMigration('1', "SELECT 1", "DELETE FROM test WHERE id = 1;"); $this->createMigration('2', "INSERT INTO test VALUES (2, 'two');", "DELETE FROM test WHERE id = 2;"); self::$application = new Application(); @@ -42,6 +42,50 @@ public function tearDown() $this->cleanEnv(); } + /** + * @expectedException \RuntimeException + */ + public function testUpMigrationWithError() + { + $this->createMigration('3', "SELECT ;", "SELECT ;"); + $command = self::$application->find('migrate:up'); + $commandTester = new CommandTester($command); + + $commandTester->execute(array( + 'command' => $command->getName(), + 'env' => 'testing' + )); + } + + /** + * @expectedException \RuntimeException + */ + public function testDownMigrationWithError() + { + $this->createMigration('3', "SELECT 1;", "SELECT ;"); + + + $command = self::$application->find('migrate:up'); + $commandTester = new CommandTester($command); + + $commandTester->execute(array( + 'command' => $command->getName(), + 'env' => 'testing' + )); + + $command = self::$application->find('migrate:down'); + $commandTester = new CommandTester($command); + + /* @var $question QuestionHelper */ + $question = $command->getHelper('question'); + $question->setInputStream(InputStreamUtil::type("yes\n")); + + $commandTester->execute(array( + 'command' => $command->getName(), + 'env' => 'testing' + )); + } + public function testUpAllPendingMigrations() { From 0b86424d59769224ee348c9038d7e65db3f3c771 Mon Sep 17 00:00:00 2001 From: Alexandre GUIDET Date: Mon, 9 Mar 2015 16:16:17 +0100 Subject: [PATCH 03/16] [twgit] Init hotfix 'hotfix-3.4.3'. From a6776c4a20aa857d28ab0f1b933a7fcc369d5349 Mon Sep 17 00:00:00 2001 From: Alexandre GUIDET Date: Mon, 9 Mar 2015 16:18:52 +0100 Subject: [PATCH 04/16] exec instead of query for multiple line query --- Migrate/Command/AbstractEnvCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Migrate/Command/AbstractEnvCommand.php b/Migrate/Command/AbstractEnvCommand.php index 7c3db0d..541739e 100644 --- a/Migrate/Command/AbstractEnvCommand.php +++ b/Migrate/Command/AbstractEnvCommand.php @@ -206,7 +206,7 @@ public function removeFromChangelog(Migration $migration) public function executeUpMigration(Migration $migration) { $this->getDb()->beginTransaction(); - $result = $this->getDb()->query($migration->getSqlUp()); + $result = $this->getDb()->exec($migration->getSqlUp()); if ($result === false) { // error while executing the migration @@ -229,7 +229,7 @@ public function executeUpMigration(Migration $migration) public function executeDownMigration(Migration $migration) { $this->getDb()->beginTransaction(); - $result = $this->getDb()->query($migration->getSqlDown()); + $result = $this->getDb()->exec($migration->getSqlDown()); if ($result === false) { // error while executing the migration From 8271ba643e2fd6875b78c57efc1ef543298a81f7 Mon Sep 17 00:00:00 2001 From: Alexandre GUIDET Date: Mon, 20 Apr 2015 10:08:45 +0200 Subject: [PATCH 05/16] [twgit] Init hotfix 'hotfix-3.4.4'. From 97af0e635b0b9a4aa47586f9c41b30df3258c9ee Mon Sep 17 00:00:00 2001 From: Alexandre GUIDET Date: Mon, 20 Apr 2015 10:16:35 +0200 Subject: [PATCH 06/16] check if the current directory is ok before runing --- Migrate/Command/AbstractEnvCommand.php | 7 ++++ Migrate/Command/CreateCommand.php | 2 + Migrate/Command/DownCommand.php | 2 + Migrate/Command/UpCommand.php | 2 + tests/Command/CreateCommandTest.php | 17 +++++++++ tests/Command/UpDownCommandTest.php | 52 ++++++++++++++++++++++++++ 6 files changed, 82 insertions(+) diff --git a/Migrate/Command/AbstractEnvCommand.php b/Migrate/Command/AbstractEnvCommand.php index 541739e..916aa10 100644 --- a/Migrate/Command/AbstractEnvCommand.php +++ b/Migrate/Command/AbstractEnvCommand.php @@ -53,6 +53,13 @@ public function getChangelogTable() return ArrayUtil::get($this->getConfig(), 'changelog'); } + protected function checkEnv() + { + if (!file_exists(getcwd() . '/.php-database-migration/environments')) { + throw new \RuntimeException("you are not in an initialized php-database-migration directory"); + } + } + protected function init(InputInterface $input, OutputInterface $output, $env = null) { $configDirectory = array(getcwd() . '/.php-database-migration/environments'); diff --git a/Migrate/Command/CreateCommand.php b/Migrate/Command/CreateCommand.php index cd823cc..d8849b1 100644 --- a/Migrate/Command/CreateCommand.php +++ b/Migrate/Command/CreateCommand.php @@ -28,6 +28,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $this->checkEnv(); + /* @var $questions QuestionHelper */ $questions = $this->getHelperSet()->get('question'); diff --git a/Migrate/Command/DownCommand.php b/Migrate/Command/DownCommand.php index 8d1e815..8b00235 100644 --- a/Migrate/Command/DownCommand.php +++ b/Migrate/Command/DownCommand.php @@ -46,6 +46,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $this->checkEnv(); + $this->init($input, $output); /* @var $questions QuestionHelper */ diff --git a/Migrate/Command/UpCommand.php b/Migrate/Command/UpCommand.php index 561a015..40804da 100644 --- a/Migrate/Command/UpCommand.php +++ b/Migrate/Command/UpCommand.php @@ -43,6 +43,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $this->checkEnv(); + $this->init($input, $output); $toExecute = $this->filterMigrationsToExecute($input, $output); diff --git a/tests/Command/CreateCommandTest.php b/tests/Command/CreateCommandTest.php index 2fd2825..ab95850 100644 --- a/tests/Command/CreateCommandTest.php +++ b/tests/Command/CreateCommandTest.php @@ -58,4 +58,21 @@ public function testExecute() $this->assertEquals($expected, $content); } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage you are not in an initialized php-database-migration directory + */ + public function testCreateNotInAnInitialisedProject() + { + $this->cleanEnv(); + + $application = new Application(); + $application->add(new CreateCommand()); + + $command = $application->find('migrate:create'); + $commandTester = new CommandTester($command); + + $commandTester->execute(array('command' => $command->getName())); + } } \ No newline at end of file diff --git a/tests/Command/UpDownCommandTest.php b/tests/Command/UpDownCommandTest.php index 82781e4..bff6771 100644 --- a/tests/Command/UpDownCommandTest.php +++ b/tests/Command/UpDownCommandTest.php @@ -352,4 +352,56 @@ public function testDownTo() $this->assertEquals($expected, $commandTester->getDisplay()); } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage you are not in an initialized php-database-migration directory + */ + public function testUpInANotInitializedDirectory() + { + $this->cleanEnv(); + + $command = self::$application->find('migrate:up'); + $commandTester = new CommandTester($command); + + $commandTester->execute(array( + 'command' => $command->getName(), + 'env' => 'testing', + )); + + $command = self::$application->find('migrate:down'); + $commandTester = new CommandTester($command); + + $commandTester->execute(array( + 'command' => $command->getName(), + 'env' => 'testing', + '--to' => '1' + )); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage you are not in an initialized php-database-migration directory + */ + public function testDownInANotInitializedDirectory() + { + $this->cleanEnv(); + + $command = self::$application->find('migrate:down'); + $commandTester = new CommandTester($command); + + $commandTester->execute(array( + 'command' => $command->getName(), + 'env' => 'testing', + )); + + $command = self::$application->find('migrate:down'); + $commandTester = new CommandTester($command); + + $commandTester->execute(array( + 'command' => $command->getName(), + 'env' => 'testing', + '--to' => '1' + )); + } } \ No newline at end of file From cedb5fd8aa5ca0f8e3bd616f477146bfe2b92cce Mon Sep 17 00:00:00 2001 From: tellim Date: Tue, 17 Nov 2015 15:27:54 +0100 Subject: [PATCH 07/16] Allow to split up/down migration into multiple sql files using the '-- @FILE' annotation --- Migrate/Migration.php | 38 ++++++++++++++++- tests/MigrationTest.php | 52 ++++++++++++++++++++++++ tests/data/feature-1/down/db1/table1.sql | 1 + tests/data/feature-1/down/db1/table2.sql | 1 + tests/data/feature-1/down/db2/table1.sql | 1 + tests/data/feature-1/rollout.sql | 17 ++++++++ tests/data/feature-1/up/db1/table1.sql | 1 + tests/data/feature-1/up/db1/table2.sql | 1 + tests/data/feature-1/up/db2/table1.sql | 1 + 9 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 tests/MigrationTest.php create mode 100644 tests/data/feature-1/down/db1/table1.sql create mode 100644 tests/data/feature-1/down/db1/table2.sql create mode 100644 tests/data/feature-1/down/db2/table1.sql create mode 100644 tests/data/feature-1/rollout.sql create mode 100644 tests/data/feature-1/up/db1/table1.sql create mode 100644 tests/data/feature-1/up/db1/table2.sql create mode 100644 tests/data/feature-1/up/db2/table1.sql diff --git a/Migrate/Migration.php b/Migrate/Migration.php index d9736c0..1233d6d 100644 --- a/Migrate/Migration.php +++ b/Migrate/Migration.php @@ -21,6 +21,9 @@ class Migration private $sqlUp; private $sqlDown; + const SQL_UP = 'SQL_UP'; + const SQL_DOWN = 'SQL_DOWN'; + /** * @return mixed */ @@ -117,6 +120,8 @@ public function setSqlUp($sqlUp) $this->sqlUp = $sqlUp; } + + /** * @return mixed */ @@ -180,8 +185,37 @@ public function load($migrationDir) @$content = file_get_contents($migrationDir . '/' . $this->getFile()); if ($content && strpos($content, '@UNDO') > 0) { $sql = explode('-- @UNDO', $content); - $this->setSqlUp($sql[0]); - $this->setSqlDown($sql[1]); + $this->setSqlUp($this->parseSQLFile($migrationDir, $sql[0])); + $this->setSqlDown($this->parseSQLFile($migrationDir, $sql[1])); + } + } + + public function parseSQLFile($migrationDir, $content = null, $sqlFile = null) { + if( $sqlFile != null ) { + @$content = file_get_contents($migrationDir . '/' . $sqlFile); + } + if($content != null) { + if( strpos($content, '-- @FILE') > 0 ) { + $buffer = ''; + $isFile = false; + $lines = explode("\n", $content); + foreach($lines as $line) { + if( strpos($line, '-- @FILE') !== false ) { + $isFile = true; + continue; + } + if( $isFile ) { + $filename = trim($line); + $buffer .= PHP_EOL . $this->parseSQLFile($migrationDir, null, $filename); + $isFile = false; + continue; + } + $buffer .= "\n" . $line; + } + return $buffer; + } else { + return $content; + } } } } \ No newline at end of file diff --git a/tests/MigrationTest.php b/tests/MigrationTest.php new file mode 100644 index 0000000..9fb8807 --- /dev/null +++ b/tests/MigrationTest.php @@ -0,0 +1,52 @@ +migration = new Migration(); + } + + + public function testLoad() { + + $this->migration->setFile('rollout.sql'); + $this->migration->load(__DIR__.'/data/feature-1/'); + + $expected =<<assertEquals($expected, $this->migration->getSqlUp() ); + + $expected =<<assertEquals($expected, $this->migration->getSqlDown() ); + + } +} \ No newline at end of file diff --git a/tests/data/feature-1/down/db1/table1.sql b/tests/data/feature-1/down/db1/table1.sql new file mode 100644 index 0000000..0992a1c --- /dev/null +++ b/tests/data/feature-1/down/db1/table1.sql @@ -0,0 +1 @@ +update db1.table1 set foo = 'foo'; \ No newline at end of file diff --git a/tests/data/feature-1/down/db1/table2.sql b/tests/data/feature-1/down/db1/table2.sql new file mode 100644 index 0000000..12daa8e --- /dev/null +++ b/tests/data/feature-1/down/db1/table2.sql @@ -0,0 +1 @@ +update db1.table2 set foo = 'foo'; \ No newline at end of file diff --git a/tests/data/feature-1/down/db2/table1.sql b/tests/data/feature-1/down/db2/table1.sql new file mode 100644 index 0000000..2863b48 --- /dev/null +++ b/tests/data/feature-1/down/db2/table1.sql @@ -0,0 +1 @@ +update db2.table1 set foo = 'foo'; \ No newline at end of file diff --git a/tests/data/feature-1/rollout.sql b/tests/data/feature-1/rollout.sql new file mode 100644 index 0000000..bd4b2bb --- /dev/null +++ b/tests/data/feature-1/rollout.sql @@ -0,0 +1,17 @@ +-- Test that file inclusion works correctly +-- Migration SQL that makes the change goes here. +-- @FILE +up/db1/table1.sql +-- @FILE +up/db1/table2.sql +-- @FILE +up/db2/table1.sql + +-- @UNDO +-- SQL to undo the change goes here. +-- @FILE +down/db1/table1.sql +-- @FILE +down/db1/table2.sql +-- @FILE +down/db2/table1.sql \ No newline at end of file diff --git a/tests/data/feature-1/up/db1/table1.sql b/tests/data/feature-1/up/db1/table1.sql new file mode 100644 index 0000000..f1eb1e5 --- /dev/null +++ b/tests/data/feature-1/up/db1/table1.sql @@ -0,0 +1 @@ +update db1.table1 set foo = 'bar'; \ No newline at end of file diff --git a/tests/data/feature-1/up/db1/table2.sql b/tests/data/feature-1/up/db1/table2.sql new file mode 100644 index 0000000..66ca31e --- /dev/null +++ b/tests/data/feature-1/up/db1/table2.sql @@ -0,0 +1 @@ +update db1.table2 set foo = 'bar'; \ No newline at end of file diff --git a/tests/data/feature-1/up/db2/table1.sql b/tests/data/feature-1/up/db2/table1.sql new file mode 100644 index 0000000..b4427a5 --- /dev/null +++ b/tests/data/feature-1/up/db2/table1.sql @@ -0,0 +1 @@ +update db2.table1 set foo = 'bar'; \ No newline at end of file From 571fcea19a74e5e038624f8a2e7fd5672cc1cd0e Mon Sep 17 00:00:00 2001 From: tellim Date: Tue, 17 Nov 2015 15:33:21 +0100 Subject: [PATCH 08/16] remove unused constants --- Migrate/Migration.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Migrate/Migration.php b/Migrate/Migration.php index 1233d6d..71ecd03 100644 --- a/Migrate/Migration.php +++ b/Migrate/Migration.php @@ -21,9 +21,6 @@ class Migration private $sqlUp; private $sqlDown; - const SQL_UP = 'SQL_UP'; - const SQL_DOWN = 'SQL_DOWN'; - /** * @return mixed */ From 399db8b7700266f8ead5f6ccdca1238a399c9888 Mon Sep 17 00:00:00 2001 From: tellim Date: Thu, 26 Nov 2015 11:17:23 +0100 Subject: [PATCH 09/16] Added nesting level check for the '-- @FILE' annotation to prevent infinite loop --- Migrate/Migration.php | 12 ++++++++---- tests/MigrationTest.php | 11 +++++++++++ tests/data/feature-infinite-loop/rollout.sql | 8 ++++++++ tests/data/feature-infinite-loop/up/db1/table1.sql | 2 ++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/data/feature-infinite-loop/rollout.sql create mode 100644 tests/data/feature-infinite-loop/up/db1/table1.sql diff --git a/Migrate/Migration.php b/Migrate/Migration.php index 71ecd03..4756dd4 100644 --- a/Migrate/Migration.php +++ b/Migrate/Migration.php @@ -187,12 +187,16 @@ public function load($migrationDir) } } - public function parseSQLFile($migrationDir, $content = null, $sqlFile = null) { + public function parseSQLFile($migrationDir, $content = null, $sqlFile = null, $nestingLevel = 1) { + if($nestingLevel > 5) { + // Do not allow more than 5 nesting level + throw new \RuntimeException(sprintf('Local migration "%s" is invalid : the "-- @FILE" annotation does not support more than 5 nesting level !', $this->getDescription())); + } if( $sqlFile != null ) { @$content = file_get_contents($migrationDir . '/' . $sqlFile); } if($content != null) { - if( strpos($content, '-- @FILE') > 0 ) { + if( strpos($content, '-- @FILE') !== false ) { $buffer = ''; $isFile = false; $lines = explode("\n", $content); @@ -203,11 +207,11 @@ public function parseSQLFile($migrationDir, $content = null, $sqlFile = null) { } if( $isFile ) { $filename = trim($line); - $buffer .= PHP_EOL . $this->parseSQLFile($migrationDir, null, $filename); + $buffer .= PHP_EOL . $this->parseSQLFile($migrationDir, null, $filename, ++$nestingLevel); $isFile = false; continue; } - $buffer .= "\n" . $line; + $buffer .= PHP_EOL . $line; } return $buffer; } else { diff --git a/tests/MigrationTest.php b/tests/MigrationTest.php index 9fb8807..65f0de4 100644 --- a/tests/MigrationTest.php +++ b/tests/MigrationTest.php @@ -49,4 +49,15 @@ public function testLoad() { $this->assertEquals($expected, $this->migration->getSqlDown() ); } + + /** + * @expectedException Exception + * @expectedExceptionMessageRegExp #^.* the "-- @FILE" annotation does not support more than 5 nesting level !# + */ + public function testInfiniteLoop() + { + + $this->migration->setFile('rollout.sql'); + $this->migration->load(__DIR__ . '/data/feature-infinite-loop/'); + } } \ No newline at end of file diff --git a/tests/data/feature-infinite-loop/rollout.sql b/tests/data/feature-infinite-loop/rollout.sql new file mode 100644 index 0000000..8175771 --- /dev/null +++ b/tests/data/feature-infinite-loop/rollout.sql @@ -0,0 +1,8 @@ +-- Test that file inclusion can't loop infinitely +-- Migration SQL that makes the change goes here. +-- @FILE +up/db1/table1.sql + + +-- @UNDO +-- SQL to undo the change goes here. diff --git a/tests/data/feature-infinite-loop/up/db1/table1.sql b/tests/data/feature-infinite-loop/up/db1/table1.sql new file mode 100644 index 0000000..f1e84b0 --- /dev/null +++ b/tests/data/feature-infinite-loop/up/db1/table1.sql @@ -0,0 +1,2 @@ +-- @FILE +up/db1/table1.sql \ No newline at end of file From 35b6952192ea8074be79a07cefb832ae16884959 Mon Sep 17 00:00:00 2001 From: tellim Date: Thu, 26 Nov 2015 14:59:55 +0100 Subject: [PATCH 10/16] Update of composer : package name --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 55bd86e..cc48636 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "name": "alwex/php-database-migration", + "name": "tellim/php-database-migration", "description": "rake and mybatis SQL migration tool", - "homepage": "https://github.com/alwex/php-database-migration", + "homepage": "https://github.com/tellim/php-database-migration", "keywords": ["rake", "mybatis", "migration", "sql"], "type": "library", "license": "MIT", From 24ac31a5d4f6081e48c9485aa9bf8ac147f6840a Mon Sep 17 00:00:00 2001 From: tellim Date: Fri, 27 Nov 2015 12:07:22 +0100 Subject: [PATCH 11/16] Fix nesting level control --- Migrate/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Migrate/Migration.php b/Migrate/Migration.php index 4756dd4..ecaec53 100644 --- a/Migrate/Migration.php +++ b/Migrate/Migration.php @@ -207,7 +207,7 @@ public function parseSQLFile($migrationDir, $content = null, $sqlFile = null, $n } if( $isFile ) { $filename = trim($line); - $buffer .= PHP_EOL . $this->parseSQLFile($migrationDir, null, $filename, ++$nestingLevel); + $buffer .= PHP_EOL . $this->parseSQLFile($migrationDir, null, $filename, ($nestingLevel+1)); $isFile = false; continue; } From 9b91e75c8a83ad7c545f3055655e6d71b3322d45 Mon Sep 17 00:00:00 2001 From: tellim Date: Fri, 27 Nov 2015 12:41:10 +0100 Subject: [PATCH 12/16] Renamed lib to original name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cc48636..529ce7c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "tellim/php-database-migration", + "name": "php-database-migration/php-database-migration", "description": "rake and mybatis SQL migration tool", "homepage": "https://github.com/tellim/php-database-migration", "keywords": ["rake", "mybatis", "migration", "sql"], From 8a5499bc7cc5eb820de4b7ce91580f3760aff075 Mon Sep 17 00:00:00 2001 From: tellim Date: Fri, 27 Nov 2015 12:56:48 +0100 Subject: [PATCH 13/16] Renamed lib to original name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 529ce7c..3615d75 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "php-database-migration/php-database-migration", + "name": "alwex/php-database-migration", "description": "rake and mybatis SQL migration tool", "homepage": "https://github.com/tellim/php-database-migration", "keywords": ["rake", "mybatis", "migration", "sql"], From 7e6c30e301128e192c15786894f017a558083883 Mon Sep 17 00:00:00 2001 From: tellim Date: Fri, 27 Nov 2015 13:01:24 +0100 Subject: [PATCH 14/16] Renamed package to php-database-migration/php-database-migration --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3615d75..529ce7c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "alwex/php-database-migration", + "name": "php-database-migration/php-database-migration", "description": "rake and mybatis SQL migration tool", "homepage": "https://github.com/tellim/php-database-migration", "keywords": ["rake", "mybatis", "migration", "sql"], From 29581955b9eb53605ccc81532d0e10c99cdf0fef Mon Sep 17 00:00:00 2001 From: tellim Date: Fri, 27 Nov 2015 14:17:02 +0100 Subject: [PATCH 15/16] exclude folders for migration includes --- Migrate/Utils/ArrayUtil.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Migrate/Utils/ArrayUtil.php b/Migrate/Utils/ArrayUtil.php index 9fa7332..781be1c 100644 --- a/Migrate/Utils/ArrayUtil.php +++ b/Migrate/Utils/ArrayUtil.php @@ -15,17 +15,13 @@ public static function get(array $array, $key) { } public static function filter(array $array) { - if (isset($array['.'])) { - unset($array['.']); + $files = array(); + foreach ($array as $file) { + if(!is_dir($file)){ + $files[] = $file; + } } - if (isset($array['..'])) { - unset($array['..']); - } - - unset($array[0]); - unset($array[1]); - - return $array; + return $files; } } \ No newline at end of file From 990ffb5bb23aabe9d5b71c7af4ab018dcc060c6c Mon Sep 17 00:00:00 2001 From: tellim Date: Fri, 27 Nov 2015 16:12:40 +0100 Subject: [PATCH 16/16] Fix for folder exclusion --- Migrate/Command/AbstractEnvCommand.php | 2 +- Migrate/Utils/ArrayUtil.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Migrate/Command/AbstractEnvCommand.php b/Migrate/Command/AbstractEnvCommand.php index fec017a..477209c 100644 --- a/Migrate/Command/AbstractEnvCommand.php +++ b/Migrate/Command/AbstractEnvCommand.php @@ -100,7 +100,7 @@ protected function init(InputInterface $input, OutputInterface $output, $env = n public function getLocalMigrations() { $fileList = scandir($this->getMigrationDir()); - $fileList = ArrayUtil::filter($fileList); + $fileList = ArrayUtil::filter($this->getMigrationDir(), $fileList); $migrations = array(); foreach ($fileList as $file) { diff --git a/Migrate/Utils/ArrayUtil.php b/Migrate/Utils/ArrayUtil.php index 781be1c..b4278e4 100644 --- a/Migrate/Utils/ArrayUtil.php +++ b/Migrate/Utils/ArrayUtil.php @@ -14,10 +14,10 @@ public static function get(array $array, $key) { return (array_key_exists($key, $array)) ? $array[$key] : null; } - public static function filter(array $array) { + public static function filter($dir, array $array) { $files = array(); foreach ($array as $file) { - if(!is_dir($file)){ + if(!is_dir(sprintf('%s/%s', $dir, $file))){ $files[] = $file; } }