From 63adc08313cabd197ae45cb80c2ade9c290d05e0 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 31 Aug 2020 21:08:16 +0100 Subject: [PATCH 1/5] #94 - Fix case of AUTO_INCREMENT option --- tests/mysql/MigrationsCest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/mysql/MigrationsCest.php b/tests/mysql/MigrationsCest.php index ed6317f..0d287e4 100644 --- a/tests/mysql/MigrationsCest.php +++ b/tests/mysql/MigrationsCest.php @@ -274,7 +274,7 @@ public function generateWithAutoIncrement(MysqlTester $I): void $I->assertEquals(4, $autoIncrement); $I->assertContains( - "'auto_increment' => '4'", + "'AUTO_INCREMENT' => '4'", file_get_contents($migrationsDir . '/1.0.0/' . $tableName . '.php') ); } @@ -323,7 +323,7 @@ public function generateWithoutAutoIncrement(MysqlTester $I): void $I->assertEquals(4, $autoIncrement); $I->assertContains( - "'auto_increment' => ''", + "'AUTO_INCREMENT' => ''", file_get_contents($migrationsDir . '/1.0.0/' . $tableName . '.php') ); } From 5c286a31c981e812d3f19a48ff1b0d788c8459ae Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 31 Aug 2020 21:44:04 +0100 Subject: [PATCH 2/5] #94 - Update README.md --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3570f55..4fee3d1 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ composer require --dev phalcon/migrations What you need for quick start: -* Configuration file in root of your project (you can also pass them as parameters inside CLI environment) +* Configuration file (ex: `migrations.php`) in root of your project (you can also pass them as parameters inside CLI environment) * Create database tables structure * Execute command to generate migrations @@ -37,6 +37,8 @@ After that you can execute that migrations (run) in another environment to creat ### Create configuration file +Configuration filename can be whatever you want. + ```php Date: Mon, 31 Aug 2020 21:49:25 +0100 Subject: [PATCH 3/5] #94 - Fix case of table options to upper --- src/Migration/Action/Generate.php | 6 +- tests/_data/issues/76/1.0.0/user_details.php | 6 +- tests/_data/issues/94/1.0.0/memory_table.php | 40 +++++++++ tests/mysql/Issue94Cest.php | 89 ++++++++++++++++++++ 4 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 tests/_data/issues/94/1.0.0/memory_table.php create mode 100644 tests/mysql/Issue94Cest.php diff --git a/src/Migration/Action/Generate.php b/src/Migration/Action/Generate.php index fe8628e..7e9b01b 100644 --- a/src/Migration/Action/Generate.php +++ b/src/Migration/Action/Generate.php @@ -328,7 +328,11 @@ public function getOptions(bool $skipAI): array { $options = []; foreach ($this->options as $name => $value) { - if ($skipAI && strtoupper($name) == 'AUTO_INCREMENT') { + /** + * All options keys must be UPPERCASE! + */ + $name = strtoupper($name); + if ($skipAI && $name == 'AUTO_INCREMENT') { $value = ''; } diff --git a/tests/_data/issues/76/1.0.0/user_details.php b/tests/_data/issues/76/1.0.0/user_details.php index 045760e..37aa7ed 100644 --- a/tests/_data/issues/76/1.0.0/user_details.php +++ b/tests/_data/issues/76/1.0.0/user_details.php @@ -85,9 +85,9 @@ public function morph() new Index('PRIMARY', ['user_id'], 'PRIMARY') ], 'options' => [ - 'table_type' => 'BASE TABLE', - 'engine' => 'InnoDB', - 'table_collation' => 'latin1_swedish_ci' + 'TABLE_TYPE' => 'BASE TABLE', + 'ENGINE' => 'InnoDB', + 'TABLE_COLLATION' => 'latin1_swedish_ci' ], ]); } diff --git a/tests/_data/issues/94/1.0.0/memory_table.php b/tests/_data/issues/94/1.0.0/memory_table.php new file mode 100644 index 0000000..6bd481e --- /dev/null +++ b/tests/_data/issues/94/1.0.0/memory_table.php @@ -0,0 +1,40 @@ +morphTable('memory_table', [ + 'columns' => [ + new Column( + 'id', + [ + 'type' => Column::TYPE_INTEGER, + 'notNull' => true, + 'autoIncrement' => true, + 'size' => 11, + 'first' => true + ] + ), + ], + 'indexes' => [ + new Index('PRIMARY', ['id'], 'PRIMARY') + ], + 'options' => [ + 'TABLE_TYPE' => 'BASE TABLE', + 'ENGINE' => 'MEMORY', + 'TABLE_COLLATION' => 'latin1_swedish_ci' + ], + ]); + } +} diff --git a/tests/mysql/Issue94Cest.php b/tests/mysql/Issue94Cest.php new file mode 100644 index 0000000..1b8d208 --- /dev/null +++ b/tests/mysql/Issue94Cest.php @@ -0,0 +1,89 @@ +wantToTest('Issue #94 - Engine "MEMORY"'); + + ob_start(); + Migrations::run([ + 'migrationsDir' => codecept_data_dir('issues/94'), + 'config' => $I->getMigrationsConfig(), + 'migrationsInDb' => true, + ]); + ob_clean(); + + $options = $I->getPhalconDb()->tableOptions('memory_table'); + + $I->assertSame('MEMORY', $options['engine']); + } + + /** + * @param MysqlTester $I + * @throws Exception + */ + public function testGenerateIssue94(MysqlTester $I): void + { + $I->wantToTest('Issue #94 - Correct options generation case (uppercase)'); + + $engine = 'MyISAM'; + $tableName = 'options_uppercase'; + $migrationsDir = codecept_output_dir(__FUNCTION__); + + $I->getPhalconDb()->createTable($tableName, '', [ + 'columns' => [ + new Column('id', [ + 'type' => Column::TYPE_INTEGER, + 'size' => 20, + 'notNull' => true, + 'autoIncrement' => true, + ]), + ], + 'indexes' => [ + new Index('PRIMARY', ['id'], 'PRIMARY') + ], + 'options' => [ + 'TABLE_TYPE' => 'BASE TABLE', + 'ENGINE' => $engine, + 'TABLE_COLLATION' => 'utf8mb4_general_ci', + ], + ]); + + /** + * Generate | Drop | Run + */ + ob_start(); + Migrations::generate([ + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), + 'tableName' => $tableName, + ]); + $I->getPhalconDb()->dropTable($tableName); + Migrations::run([ + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), + 'migrationsInDb' => true, + ]); + ob_clean(); + + $I->assertSame($engine, $I->getPhalconDb()->tableOptions($tableName)['engine']); + } +} From fc197523416804edb927336d26274ff670f049be Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 31 Aug 2020 21:49:39 +0100 Subject: [PATCH 4/5] #94 - Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 244cecf..bc4646b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# [2.1.4](https://github.com/phalcon/migrations/releases/tag/v2.1.4) (2020-08-31) +- Fixed 'options' table definition ([#94](https://github.com/phalcon/migrations/issues/94)) + # [2.1.3](https://github.com/phalcon/migrations/releases/tag/v2.1.3) (2020-08-29) - Improved tests codebase ([#86](https://github.com/phalcon/migrations/issues/86)) - Fixed `.phar` compilation ([#91](https://github.com/phalcon/migrations/issues/85)) From c3ec32227d831e20a72a3977383faf6b2839da60 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 31 Aug 2020 22:05:09 +0100 Subject: [PATCH 5/5] #94 - Update deprecation config phpstan.neon.dist --- phpstan.neon.dist | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f6c3a61..d395c34 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,6 @@ parameters: - bootstrap: %rootDir%/../../../vendor/autoload.php + bootstrapFiles: + - %rootDir%/../../../vendor/autoload.php ignoreErrors: - '#Parameter \#1 \$eventsManager of method Phalcon#'