Skip to content

Commit

Permalink
Merge pull request #1736 from tarlepp/feat/migration-template
Browse files Browse the repository at this point in the history
Feat - Added proper platform checks to migration files
  • Loading branch information
tarlepp committed Apr 16, 2022
2 parents 3606dd9 + 410d7b4 commit 0fa1a33
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 103 deletions.
200 changes: 100 additions & 100 deletions .idea/symfony-flex-backend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions migrations/Version20211118171749.php
Expand Up @@ -5,6 +5,7 @@
namespace DoctrineMigrations;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

Expand All @@ -18,7 +19,7 @@ final class Version20211118171749 extends AbstractMigration
*/
public function getDescription(): string
{
return 'TODO: Describe reason for this migration';
return 'Initial database structure';
}

/**
Expand All @@ -28,7 +29,7 @@ public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() !== 'mysql',
!$this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform,
'Migration can only be executed safely on \'mysql\'.'
);

Expand Down Expand Up @@ -71,7 +72,7 @@ public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() !== 'mysql',
!$this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform,
'Migration can only be executed safely on \'mysql\'.'
);

Expand Down
14 changes: 14 additions & 0 deletions migrations/Version20220312135411.php
@@ -1,8 +1,10 @@
<?php
declare(strict_types = 1);

// phpcs:ignoreFile
namespace DoctrineMigrations;

use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

Expand All @@ -21,6 +23,12 @@ public function getDescription(): string

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform,
'Migration can only be executed safely on \'mysql\'.'
);

$this->addSql('ALTER TABLE log_login_failure DROP FOREIGN KEY FK_EDB4AF3A76ED395');
$this->addSql('ALTER TABLE log_login_failure ADD CONSTRAINT FK_EDB4AF3A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
}
Expand All @@ -30,6 +38,12 @@ public function up(Schema $schema): void
*/
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform,
'Migration can only be executed safely on \'mysql\'.'
);

$this->addSql('ALTER TABLE log_login_failure DROP FOREIGN KEY FK_EDB4AF3A76ED395');
$this->addSql('ALTER TABLE log_login_failure ADD CONSTRAINT FK_EDB4AF3A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
}
Expand Down

0 comments on commit 0fa1a33

Please sign in to comment.