Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 53a4171

Browse files
authored
Merge pull request #24 from Insolita/fix_bug_with_empty_migrations
bugfix #3
2 parents ae488a3 + c441cfe commit 53a4171

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/lib/MigrationBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ public function buildFresh():MigrationModel
9595
$this->migration = new MigrationModel($this->model, true);
9696
$this->uniqueColumns = $this->model->getUniqueColumnsList();
9797
$this->newColumns = $this->model->attributesToColumnSchema();
98+
if (empty($this->newColumns)) {
99+
return $this->migration;
100+
}
98101
$builder = $this->recordBuilder;
99102
$tableName = $this->model->getTableAlias();
103+
100104
$this->migration->addUpCode($builder->createTable($tableName, $this->newColumns, $this->uniqueColumns))
101105
->addDownCode($builder->dropTable($tableName));
102106
if ($this->isPostgres) {

src/lib/MigrationsGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function generate(array $models):array
4949
$this->migrations[$model->tableAlias] = $migration;
5050
}
5151
}
52-
return $this->sortMigrationsByDeps();
52+
return !empty($this->migrations) ? $this->sortMigrationsByDeps() : [];
5353
}
5454

5555
/**

tests/unit/MigrationsGeneratorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
class MigrationsGeneratorTest extends TestCase
1717
{
1818

19+
public function testNoMigrations()
20+
{
21+
$this->prepareTempDir();
22+
$this->mockApplication($this->mockDbSchemaAsEmpty());
23+
$model = new DbModel(['name' => 'dummy', 'tableName' => 'dummy', 'attributes' => []]);
24+
$generator = new MigrationsGenerator();
25+
$migrations = $generator->generate([$model]);
26+
self::assertEmpty($migrations);
27+
}
1928
/**
2029
* @dataProvider simpleDbModelsProvider
2130
* @param array|DbModel[] $dbModels

0 commit comments

Comments
 (0)