-
-
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.
#2 - Add test case with 'SET FOREIGN_KEY_CHECKS'
- Loading branch information
Showing
3 changed files
with
177 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Migrations\Tests\Integration; | ||
|
||
use Phalcon\Migrations\Migrations; | ||
use function Phalcon\Migrations\Tests\root_path; | ||
|
||
class Issue2Test extends IntegrationTestCase | ||
{ | ||
public function testDisableEnableForeignKeyChecks(): void | ||
{ | ||
Migrations::run([ | ||
'migrationsDir' => root_path('tests/var/issues/2'), | ||
'config' => self::$generateConfig, | ||
'migrationsInDb' => true, | ||
]); | ||
|
||
$this->assertTrue($this->db->tableExists('accessToken')); | ||
$this->assertTrue($this->db->tableExists('client')); | ||
$this->assertArrayHasKey('fk_accessToken_client_1', $this->db->describeReferences('accessToken')); | ||
} | ||
} |
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,90 @@ | ||
<?php | ||
|
||
use Phalcon\Db\Column; | ||
use Phalcon\Db\Index; | ||
use Phalcon\Db\Reference; | ||
use Phalcon\Migrations\Mvc\Model\Migration; | ||
|
||
class AccessTokenMigration_1 extends Migration | ||
{ | ||
/** | ||
* Define the table structure | ||
* | ||
* @return void | ||
* @throws \Phalcon\Db\Exception | ||
*/ | ||
public function morph() | ||
{ | ||
$this->getConnection()->execute('SET FOREIGN_KEY_CHECKS=0;'); | ||
|
||
$this->morphTable('accessToken', [ | ||
'columns' => [ | ||
new Column( | ||
'token', | ||
[ | ||
'type' => Column::TYPE_VARCHAR, | ||
'notNull' => true, | ||
'size' => 80, | ||
'first' => true, | ||
] | ||
), | ||
new Column( | ||
'clientId', | ||
[ | ||
'type' => Column::TYPE_VARCHAR, | ||
'size' => 80, | ||
'after' => 'token', | ||
] | ||
), | ||
new Column( | ||
'userId', | ||
[ | ||
'type' => Column::TYPE_VARCHAR, | ||
'size' => 80, | ||
'after' => 'clientId', | ||
] | ||
), | ||
|
||
], | ||
'indexes' => [ | ||
new Index('accessToken_pkey', ['token'], 'PRIMARY'), | ||
], | ||
'references' => [ | ||
new Reference( | ||
'fk_accessToken_client_1', | ||
[ | ||
'referencedTable' => 'client', | ||
'referencedSchema' => 'public', | ||
'columns' => ['clientId'], | ||
'referencedColumns' => ['id'], | ||
'onUpdate' => 'NO ACTION', | ||
'onDelete' => 'NO ACTION', | ||
] | ||
), | ||
], | ||
] | ||
); | ||
|
||
$this->getConnection()->execute('SET FOREIGN_KEY_CHECKS=1;'); | ||
} | ||
|
||
/** | ||
* Run the migrations | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Reverse the migrations | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
$this->getConnection()->dropTable('accessToken'); | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
use Phalcon\Db\Column; | ||
use Phalcon\Db\Index; | ||
use Phalcon\Migrations\Mvc\Model\Migration; | ||
|
||
class ClientMigration_1 extends Migration | ||
{ | ||
/** | ||
* Define the table structure | ||
* | ||
* @return void | ||
* @throws \Phalcon\Db\Exception | ||
*/ | ||
public function morph() | ||
{ | ||
$this->morphTable('client', [ | ||
'columns' => [ | ||
new Column( | ||
'id', | ||
[ | ||
'type' => Column::TYPE_VARCHAR, | ||
'notNull' => true, | ||
'size' => 80, | ||
'first' => true, | ||
] | ||
), | ||
new Column( | ||
'name', | ||
[ | ||
'type' => Column::TYPE_VARCHAR, | ||
'notNull' => true, | ||
'size' => 80, | ||
'first' => true, | ||
] | ||
), | ||
], | ||
'indexes' => [ | ||
new Index('client_pkey', ['id'], 'PRIMARY'), | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Run the migrations | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Reverse the migrations | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
$this->getConnection()->dropTable('client'); | ||
} | ||
} |