Skip to content

Commit e934a3d

Browse files
committed
Run actual generated migrations in tests
1 parent 1adc170 commit e934a3d

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/lib/migrations/MigrationRecordBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public function addIndex(string $tableAlias, string $indexName, array $columns,
244244
{
245245
$indexType = $using === null ? 'false' : "'".ColumnToCode::escapeQuotes($using)."'";
246246

247-
if (ApiGenerator::isPostgres() && $using && stripos($using, '(') !== false) {
247+
if ($using && (stripos($using, '(') !== false) && ApiGenerator::isPostgres()) {
248248
// if `$using` is `gin(to_tsvector('english', search::text))`
249249
$r = explode('(', $using, 2);
250250
$indexType = "'".$r[0]."'"; # `gin`

tests/unit/MultiDbFreshMigrationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function testMaria()
2626
$this->assertInstanceOf(MySqlSchema::class, Yii::$app->db->schema);
2727
$testFile = Yii::getAlias('@specs/blog.php');
2828
$this->runGenerator($testFile, $dbName);
29+
$this->runActualMigrations($dbName, 5);
2930
$expectedFiles = $this->findExpectedFiles($testFile, $dbName);
3031
$actualFiles = $this->findActualFiles();
3132
$this->assertEquals($expectedFiles, $actualFiles);
@@ -39,6 +40,7 @@ public function testPostgres()
3940
$this->assertInstanceOf(PgSqlSchema::class, Yii::$app->db->schema);
4041
$testFile = Yii::getAlias('@specs/blog.php');
4142
$this->runGenerator($testFile, $dbName);
43+
$this->runActualMigrations($dbName, 5);
4244
$expectedFiles = $this->findExpectedFiles($testFile, $dbName);
4345
$actualFiles = $this->findActualFiles();
4446
$this->assertEquals($expectedFiles, $actualFiles);
@@ -52,6 +54,7 @@ public function testMysql()
5254
$this->assertInstanceOf(MySqlSchema::class, Yii::$app->db->schema);
5355
$testFile = Yii::getAlias('@specs/blog.php');
5456
$this->runGenerator($testFile, $dbName);
57+
$this->runActualMigrations($dbName, 5);
5558
$expectedFiles = $this->findExpectedFiles($testFile, $dbName);
5659
$actualFiles = $this->findActualFiles();
5760
$this->assertEquals($expectedFiles, $actualFiles);

tests/unit/MultiDbSecondaryMigrationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testPostgresCustom()
2222
$this->assertInstanceOf(PgSqlSchema::class, Yii::$app->db->schema);
2323
$testFile = Yii::getAlias('@specs/postgres_custom.php');
2424
$this->runGenerator($testFile, $dbName);
25-
$this->runActualMigrations('pgsql', 1);
25+
$this->runActualMigrations($dbName, 1);
2626
$expectedFiles = $this->findExpectedFiles($testFile, $dbName);
2727
$actualFiles = $this->findActualFiles();
2828
$this->assertEquals($expectedFiles, $actualFiles);
@@ -36,6 +36,7 @@ public function testMaria()
3636
$this->assertInstanceOf(MySqlSchema::class, Yii::$app->db->schema);
3737
$testFile = Yii::getAlias('@specs/blog_v2.php');
3838
$this->runGenerator($testFile, $dbName);
39+
// $this->runActualMigrations($dbName, 6); since PK is changed, no need to run actual migrations here
3940
$expectedFiles = $this->findExpectedFiles($testFile, $dbName);
4041
$actualFiles = $this->findActualFiles();
4142
$this->assertEquals($expectedFiles, $actualFiles);

0 commit comments

Comments
 (0)