Skip to content

Commit dce2ec7

Browse files
committed
fix: enhance database creation by ensuring migration table is dropped before running migrations.
1 parent 848d8ef commit dce2ec7

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

migrations/m250707_103609_tree.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public function safeUp()
1010
{
1111
$primaryKey = $this->db->driverName === 'oci'
1212
? 'NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'
13-
: $this->primaryKey();
13+
: $this->primaryKey()->notNull();
1414

1515
$nameColumn = $this->db->driverName === 'oci'
16-
? $this->string(4000)->notNull()
16+
? $this->string()->notNull()
1717
: $this->text()->notNull();
1818

1919
$this->createTable('{{%tree}}', [

tests/TestCase.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ protected function buildFlatXMLDataSet(array $dataSet): string
169169

170170
protected function createDatabase(): void
171171
{
172-
$this->runMigrate('down', ['all']);
172+
$command = $this->getDb()->createCommand();
173+
174+
if ($this->getDb()->getTableSchema('migration', true) !== null) {
175+
$command->dropTable('migration')->execute();
176+
}
177+
178+
$this->runMigrate('down', ['all' => true]);
173179
$this->runMigrate('up');
174180
}
175181

@@ -298,30 +304,6 @@ protected function getDataSetMultipleTree(): array
298304
return array_values($dataSetMultipleTree);
299305
}
300306

301-
/**
302-
* @phpstan-param array<string, mixed> $params
303-
*/
304-
protected function runMigrate(string $action, array $params = []): mixed
305-
{
306-
$migrate = new EchoMigrateController(
307-
'migrate',
308-
Yii::$app,
309-
[
310-
'migrationPath' => dirname(__DIR__) . '/migrations',
311-
'interactive' => false,
312-
],
313-
);
314-
315-
ob_start();
316-
ob_implicit_flush(false);
317-
318-
$result = $migrate->run($action, $params);
319-
320-
ob_get_clean();
321-
322-
return $result;
323-
}
324-
325307
protected function loadFixtureXML(string $fileName): SimpleXMLElement
326308
{
327309
$filePath = "{$this->fixtureDirectory}/{$fileName}";
@@ -393,6 +375,30 @@ protected function replaceQuotes(string $sql): string
393375
};
394376
}
395377

378+
/**
379+
* @phpstan-param array<string, mixed> $params
380+
*/
381+
protected function runMigrate(string $action, array $params = []): mixed
382+
{
383+
$migrate = new EchoMigrateController(
384+
'migrate',
385+
Yii::$app,
386+
[
387+
'migrationPath' => dirname(__DIR__) . '/migrations',
388+
'interactive' => false,
389+
],
390+
);
391+
392+
ob_start();
393+
ob_implicit_flush(false);
394+
395+
$result = $migrate->run($action, $params);
396+
397+
ob_get_clean();
398+
399+
return $result;
400+
}
401+
396402
/**
397403
* Applies database updates to tree nodes.
398404
*

0 commit comments

Comments
 (0)