-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix using UUID migration with sqlite
- Loading branch information
Showing
7 changed files
with
294 additions
and
2 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
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,171 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nucleos\Doctrine\Tests\Bridge\Symfony\App\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version_1_0_0 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Initial structure'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->createMeal($schema); | ||
$this->createMealCategory($schema); | ||
$this->createMealAttribute($schema); | ||
$this->createIngredient($schema); | ||
$this->createCategory($schema); | ||
$this->createMenu($schema); | ||
$this->createMealPage($schema); | ||
$this->createPageCategory($schema); | ||
$this->createAttribute($schema); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->throwIrreversibleMigrationException(); | ||
} | ||
|
||
private function createMeal(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__meal'); | ||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
]); | ||
$table->addColumn('name', Types::STRING, [ | ||
'length' => 50, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
} | ||
|
||
private function createMealCategory(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__meal_category'); | ||
$table->addColumn('meal_id', Types::INTEGER); | ||
$table->addColumn('category_id', Types::INTEGER); | ||
$table->addIndex(['meal_id']); | ||
$table->addIndex(['category_id']); | ||
$table->addForeignKeyConstraint('acme__meal', ['meal_id'], ['id']); | ||
$table->addForeignKeyConstraint('acme__category', ['category_id'], ['id']); | ||
$table->setPrimaryKey(['meal_id', 'category_id']); | ||
} | ||
|
||
private function createMealAttribute(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__meal_attribute'); | ||
$table->addColumn('attribute_id', Types::INTEGER); | ||
$table->addColumn('meal_id', Types::INTEGER); | ||
$table->addIndex(['attribute_id']); | ||
$table->addIndex(['meal_id']); | ||
$table->addForeignKeyConstraint('acme__attribute', ['attribute_id'], ['id']); | ||
$table->addForeignKeyConstraint('acme__meal', ['meal_id'], ['id']); | ||
$table->setPrimaryKey(['attribute_id', 'meal_id']); | ||
} | ||
|
||
private function createIngredient(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__ingredient'); | ||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
]); | ||
$table->addColumn('meal_id', Types::INTEGER, [ | ||
'notnull' => false, | ||
]); | ||
$table->addColumn('name', Types::STRING, [ | ||
'length' => 50, | ||
]); | ||
$table->addIndex(['meal_id']); | ||
$table->addForeignKeyConstraint('acme__meal', ['meal_id'], ['id']); | ||
$table->setPrimaryKey(['id']); | ||
} | ||
|
||
private function createCategory(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__category'); | ||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
]); | ||
$table->addColumn('name', Types::STRING, [ | ||
'length' => 50, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
*/ | ||
private function createMenu(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__menu'); | ||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
]); | ||
$table->addColumn('name', Types::STRING, [ | ||
'length' => 50, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
} | ||
|
||
private function createMealPage(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__page'); | ||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
]); | ||
$table->addColumn('menu_id', Types::INTEGER, [ | ||
'notnull' => false, | ||
]); | ||
$table->addColumn('name', Types::STRING, [ | ||
'length' => 50, | ||
]); | ||
$table->addIndex(['menu_id']); | ||
$table->addForeignKeyConstraint('acme__menu', ['menu_id'], ['id']); | ||
$table->setPrimaryKey(['id']); | ||
} | ||
|
||
private function createPageCategory(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__page_category'); | ||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
]); | ||
$table->addColumn('page_id', Types::INTEGER); | ||
$table->addColumn('category_id', Types::INTEGER, [ | ||
'notnull' => false, | ||
]); | ||
$table->addColumn('description', Types::TEXT, [ | ||
'notnull' => false, | ||
]); | ||
$table->addIndex(['page_id']); | ||
$table->addIndex(['category_id']); | ||
$table->addForeignKeyConstraint('acme__page', ['page_id'], ['id']); | ||
$table->addForeignKeyConstraint('acme__category', ['category_id'], ['id']); | ||
$table->setPrimaryKey(['id']); | ||
} | ||
|
||
private function createAttribute(Schema $schema): void | ||
{ | ||
$table = $schema->createTable('acme__attribute'); | ||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
]); | ||
$table->addColumn('name', Types::STRING, [ | ||
'length' => 50, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nucleos\Doctrine\Tests\Bridge\Symfony\App\Migrations; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
use Nucleos\Doctrine\Migration\IdToUuidMigration; | ||
use Psr\Log\LoggerInterface; | ||
|
||
final class Version_2_0_0 extends AbstractMigration | ||
{ | ||
private IdToUuidMigration $idToUuidMigration; | ||
|
||
public function __construct(Connection $connection, LoggerInterface $logger) | ||
{ | ||
parent::__construct($connection, $logger); | ||
|
||
$this->idToUuidMigration = new IdToUuidMigration($this->connection, $logger); | ||
} | ||
|
||
public function getDescription(): string | ||
{ | ||
return 'UUID migration'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->idToUuidMigration->migrate('acme__meal'); | ||
$this->idToUuidMigration->migrate('acme__ingredient'); | ||
$this->idToUuidMigration->migrate('acme__attribute'); | ||
$this->idToUuidMigration->migrate('acme__category'); | ||
$this->idToUuidMigration->migrate('acme__page'); | ||
$this->idToUuidMigration->migrate('acme__menu'); | ||
$this->idToUuidMigration->migrate('acme__page_category'); | ||
} | ||
} |
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nucleos\Doctrine\Tests\Migration; | ||
|
||
use Nucleos\Doctrine\Tests\Bridge\Symfony\App\AppKernel; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
final class MigrationTest extends KernelTestCase | ||
{ | ||
public function testMigrateUp(): void | ||
{ | ||
$kernel = self::createKernel(); | ||
$kernel->boot(); | ||
|
||
$application = new Application($kernel); | ||
$application->setAutoExit(false); | ||
|
||
$this->runCommand($application, 'doctrine:database:drop', [ | ||
'--force' => true, | ||
'--quiet' => true, | ||
]); | ||
$this->runCommand($application, 'doctrine:database:create', [ | ||
'--quiet' => true, | ||
]); | ||
$this->runCommand($application, 'doctrine:migrations:migrate', [ | ||
'--no-interaction' => true, | ||
'--allow-no-migration' => true, | ||
'-v' => true, | ||
]); | ||
} | ||
|
||
protected static function getKernelClass(): string | ||
{ | ||
return AppKernel::class; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $arguments | ||
*/ | ||
private function runCommand(Application $application, string $command, array $arguments): void | ||
{ | ||
$arguments['command'] =$command; | ||
|
||
$status = $application->run(new ArrayInput($arguments)); | ||
|
||
static::assertSame(Command::SUCCESS, $status, sprintf('Command "%s" failed', $command)); | ||
} | ||
} |