Skip to content

Commit 286988c

Browse files
authored
Merge pull request #98 from phalcon/#94-fix-engine-declaration
#94 - Fixed engine and another table options declaration
2 parents 0046c5b + c3ec322 commit 286988c

File tree

8 files changed

+157
-8
lines changed

8 files changed

+157
-8
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# [2.1.4](https://github.com/phalcon/migrations/releases/tag/v2.1.4) (2020-08-31)
2+
- Fixed 'options' table definition ([#94](https://github.com/phalcon/migrations/issues/94))
3+
14
# [2.1.3](https://github.com/phalcon/migrations/releases/tag/v2.1.3) (2020-08-29)
25
- Improved tests codebase ([#86](https://github.com/phalcon/migrations/issues/86))
36
- Fixed `.phar` compilation ([#91](https://github.com/phalcon/migrations/issues/85))

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ composer require --dev phalcon/migrations
2929

3030
What you need for quick start:
3131

32-
* Configuration file in root of your project (you can also pass them as parameters inside CLI environment)
32+
* Configuration file (ex: `migrations.php`) in root of your project (you can also pass them as parameters inside CLI environment)
3333
* Create database tables structure
3434
* Execute command to generate migrations
3535

3636
After that you can execute that migrations (run) in another environment to create same DB structure.
3737

3838
### Create configuration file
3939

40+
Configuration filename can be whatever you want.
41+
4042
```php
4143
<?php
4244

@@ -72,12 +74,22 @@ return new Config([
7274
vendor/bin/phalcon-migrations generate
7375
```
7476

77+
Or if you have ready to use configuration file.
78+
```bash
79+
vendor/bin/phalcon-migrations generate --config=migrations.php
80+
```
81+
7582
### Run migrations
7683

7784
```bash
7885
vendor/bin/phalcon-migrations run
7986
```
8087

88+
Or if you have ready to use configuration file.
89+
```bash
90+
vendor/bin/phalcon-migrations run --config=migrations.php
91+
```
92+
8193
### List existing migrations
8294

8395
```bash

phpstan.neon.dist

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
parameters:
2-
bootstrap: %rootDir%/../../../vendor/autoload.php
2+
bootstrapFiles:
3+
- %rootDir%/../../../vendor/autoload.php
34

45
ignoreErrors:
56
- '#Parameter \#1 \$eventsManager of method Phalcon#'

src/Migration/Action/Generate.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ public function getOptions(bool $skipAI): array
328328
{
329329
$options = [];
330330
foreach ($this->options as $name => $value) {
331-
if ($skipAI && strtoupper($name) == 'AUTO_INCREMENT') {
331+
/**
332+
* All options keys must be UPPERCASE!
333+
*/
334+
$name = strtoupper($name);
335+
if ($skipAI && $name == 'AUTO_INCREMENT') {
332336
$value = '';
333337
}
334338

tests/_data/issues/76/1.0.0/user_details.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public function morph()
8585
new Index('PRIMARY', ['user_id'], 'PRIMARY')
8686
],
8787
'options' => [
88-
'table_type' => 'BASE TABLE',
89-
'engine' => 'InnoDB',
90-
'table_collation' => 'latin1_swedish_ci'
88+
'TABLE_TYPE' => 'BASE TABLE',
89+
'ENGINE' => 'InnoDB',
90+
'TABLE_COLLATION' => 'latin1_swedish_ci'
9191
],
9292
]);
9393
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use Phalcon\Db\Column;
4+
use Phalcon\Db\Index;
5+
use Phalcon\Migrations\Mvc\Model\Migration;
6+
7+
class MemoryTableMigration_100 extends Migration
8+
{
9+
/**
10+
* Define the table structure
11+
*
12+
* @return void
13+
* @throws \Phalcon\Db\Exception
14+
*/
15+
public function morph()
16+
{
17+
$this->morphTable('memory_table', [
18+
'columns' => [
19+
new Column(
20+
'id',
21+
[
22+
'type' => Column::TYPE_INTEGER,
23+
'notNull' => true,
24+
'autoIncrement' => true,
25+
'size' => 11,
26+
'first' => true
27+
]
28+
),
29+
],
30+
'indexes' => [
31+
new Index('PRIMARY', ['id'], 'PRIMARY')
32+
],
33+
'options' => [
34+
'TABLE_TYPE' => 'BASE TABLE',
35+
'ENGINE' => 'MEMORY',
36+
'TABLE_COLLATION' => 'latin1_swedish_ci'
37+
],
38+
]);
39+
}
40+
}

tests/mysql/Issue94Cest.php

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Phalcon\Migrations\Tests\Mysql;
6+
7+
use MysqlTester;
8+
use Phalcon\Db\Column;
9+
use Phalcon\Db\Exception;
10+
use Phalcon\Db\Index;
11+
use Phalcon\Migrations\Migrations;
12+
13+
/**
14+
* @see https://github.com/phalcon/migrations/issues/94
15+
*/
16+
final class Issue94Cest
17+
{
18+
/**
19+
* @param MysqlTester $I
20+
* @throws Exception
21+
*/
22+
public function testIssue94(MysqlTester $I): void
23+
{
24+
$I->wantToTest('Issue #94 - Engine "MEMORY"');
25+
26+
ob_start();
27+
Migrations::run([
28+
'migrationsDir' => codecept_data_dir('issues/94'),
29+
'config' => $I->getMigrationsConfig(),
30+
'migrationsInDb' => true,
31+
]);
32+
ob_clean();
33+
34+
$options = $I->getPhalconDb()->tableOptions('memory_table');
35+
36+
$I->assertSame('MEMORY', $options['engine']);
37+
}
38+
39+
/**
40+
* @param MysqlTester $I
41+
* @throws Exception
42+
*/
43+
public function testGenerateIssue94(MysqlTester $I): void
44+
{
45+
$I->wantToTest('Issue #94 - Correct options generation case (uppercase)');
46+
47+
$engine = 'MyISAM';
48+
$tableName = 'options_uppercase';
49+
$migrationsDir = codecept_output_dir(__FUNCTION__);
50+
51+
$I->getPhalconDb()->createTable($tableName, '', [
52+
'columns' => [
53+
new Column('id', [
54+
'type' => Column::TYPE_INTEGER,
55+
'size' => 20,
56+
'notNull' => true,
57+
'autoIncrement' => true,
58+
]),
59+
],
60+
'indexes' => [
61+
new Index('PRIMARY', ['id'], 'PRIMARY')
62+
],
63+
'options' => [
64+
'TABLE_TYPE' => 'BASE TABLE',
65+
'ENGINE' => $engine,
66+
'TABLE_COLLATION' => 'utf8mb4_general_ci',
67+
],
68+
]);
69+
70+
/**
71+
* Generate | Drop | Run
72+
*/
73+
ob_start();
74+
Migrations::generate([
75+
'migrationsDir' => $migrationsDir,
76+
'config' => $I->getMigrationsConfig(),
77+
'tableName' => $tableName,
78+
]);
79+
$I->getPhalconDb()->dropTable($tableName);
80+
Migrations::run([
81+
'migrationsDir' => $migrationsDir,
82+
'config' => $I->getMigrationsConfig(),
83+
'migrationsInDb' => true,
84+
]);
85+
ob_clean();
86+
87+
$I->assertSame($engine, $I->getPhalconDb()->tableOptions($tableName)['engine']);
88+
}
89+
}

tests/mysql/MigrationsCest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function generateWithAutoIncrement(MysqlTester $I): void
274274

275275
$I->assertEquals(4, $autoIncrement);
276276
$I->assertContains(
277-
"'auto_increment' => '4'",
277+
"'AUTO_INCREMENT' => '4'",
278278
file_get_contents($migrationsDir . '/1.0.0/' . $tableName . '.php')
279279
);
280280
}
@@ -323,7 +323,7 @@ public function generateWithoutAutoIncrement(MysqlTester $I): void
323323

324324
$I->assertEquals(4, $autoIncrement);
325325
$I->assertContains(
326-
"'auto_increment' => ''",
326+
"'AUTO_INCREMENT' => ''",
327327
file_get_contents($migrationsDir . '/1.0.0/' . $tableName . '.php')
328328
);
329329
}

0 commit comments

Comments
 (0)