-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#53 - Fix running timestamp based migrations
- Loading branch information
Showing
5 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Phalcon Migrations. | ||
* | ||
* (c) Phalcon Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Migrations\Tests\Integration\MySQL; | ||
|
||
use Phalcon\Db\Column; | ||
use Phalcon\Migrations\Migrations; | ||
use Phalcon\Migrations\Script\ScriptException; | ||
use Phalcon\Mvc\Model\Exception; | ||
|
||
use function Phalcon\Migrations\Tests\root_path; | ||
|
||
final class TimestampedVersionTest extends MySQLIntegrationTestCase | ||
{ | ||
/** | ||
* @throws ScriptException | ||
* @throws Exception | ||
* @throws \Exception | ||
*/ | ||
public function testSingleVersion(): void | ||
{ | ||
$options = $this->getOptions(root_path('tests/var/output/timestamp-single-version')); | ||
|
||
$tableName = 'timestamp-versions-1'; | ||
$this->db->createTable($tableName, '', [ | ||
'columns' => [ | ||
new Column('name', [ | ||
'type' => Column::TYPE_VARCHAR, | ||
'size' => 25, | ||
]), | ||
], | ||
]); | ||
|
||
Migrations::generate($options); | ||
$this->db->dropTable($tableName); | ||
Migrations::run($options); | ||
|
||
$this->assertTrue($this->db->tableExists($tableName)); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* @throws ScriptException | ||
* @throws \Exception | ||
*/ | ||
public function testSeveralVersions(): void | ||
{ | ||
$options = $this->getOptions(root_path('tests/var/output/timestamp-several-versions')); | ||
|
||
/** | ||
* Generate first version | ||
*/ | ||
$tableName1 = 'timestamp-versions-2'; | ||
$this->db->createTable($tableName1, '', [ | ||
'columns' => [ | ||
new Column('name', [ | ||
'type' => Column::TYPE_VARCHAR, | ||
'size' => 25, | ||
]), | ||
], | ||
]); | ||
|
||
Migrations::generate($options); | ||
|
||
/** | ||
* Generate second version | ||
*/ | ||
$tableName2 = 'timestamp-versions-3'; | ||
$this->db->createTable($tableName2, '', [ | ||
'columns' => [ | ||
new Column('name', [ | ||
'type' => Column::TYPE_VARCHAR, | ||
'size' => 25, | ||
]), | ||
], | ||
]); | ||
|
||
Migrations::generate($options); | ||
|
||
/** | ||
* Drop tables and run migrations | ||
*/ | ||
$this->db->dropTable($tableName1); | ||
$this->db->dropTable($tableName2); | ||
Migrations::run($options); | ||
|
||
$this->assertTrue($this->db->tableExists($tableName1)); | ||
$this->assertTrue($this->db->tableExists($tableName2)); | ||
} | ||
|
||
private function getOptions(string $path): array | ||
{ | ||
return [ | ||
'migrationsDir' => $path, | ||
'config' => self::$generateConfig, | ||
'tableName' => '@', | ||
'descr' => '1', | ||
'tsBased' => true, | ||
'migrationsInDb' => true, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters