From 342ed382e3dabbab37569ae0b327e2d65167caa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 9 Apr 2023 00:04:13 +0200 Subject: [PATCH] Properly mark the tinyint column with a comment, so that migrations can properly detect that no changes are needed --- config/packages/doctrine.yaml | 2 + migrations/Version20230408213957.php | 2 + migrations/Version20230408220140.php | 31 +++++++++++++++ src/Doctrine/Types/TinyIntType.php | 47 +++++++++++++++++++++++ src/Entity/LogSystem/AbstractLogEntry.php | 2 +- 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20230408220140.php create mode 100644 src/Doctrine/Types/TinyIntType.php diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 20c1001e..5cdb115a 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -12,6 +12,8 @@ doctrine: class: App\Doctrine\Types\UTCDateTimeType big_decimal: class: App\Doctrine\Types\BigDecimalType + tinyint: + class: App\Doctrine\Types\TinyIntType schema_filter: ~^(?!internal)~ # Only enable this when needed diff --git a/migrations/Version20230408213957.php b/migrations/Version20230408213957.php index 17b3c8a1..bef25a5f 100644 --- a/migrations/Version20230408213957.php +++ b/migrations/Version20230408213957.php @@ -28,6 +28,7 @@ final class Version20230408213957 extends AbstractMultiPlatformMigration } $this->addSql('ALTER TABLE projects CHANGE description description LONGTEXT DEFAULT \'\' NOT NULL'); $this->addSql('ALTER TABLE users CHANGE permissions_data permissions_data LONGTEXT DEFAULT \'[]\' NOT NULL COMMENT \'(DC2Type:json)\', CHANGE saml_user saml_user TINYINT(1) NOT NULL, CHANGE about_me about_me LONGTEXT DEFAULT \'\' NOT NULL'); + $this->addSql('ALTER TABLE log CHANGE level level TINYINT NOT NULL COMMENT \'(DC2Type:tinyint)\''); } public function mySQLDown(Schema $schema): void @@ -37,6 +38,7 @@ final class Version20230408213957 extends AbstractMultiPlatformMigration $this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) NOT NULL'); $this->addSql('ALTER TABLE projects CHANGE description description LONGTEXT NOT NULL'); $this->addSql('ALTER TABLE `users` CHANGE about_me about_me LONGTEXT NOT NULL, CHANGE saml_user saml_user TINYINT(1) DEFAULT 0 NOT NULL, CHANGE permissions_data permissions_data LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\''); + $this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) NOT NULL'); } public function sqLiteUp(Schema $schema): void diff --git a/migrations/Version20230408220140.php b/migrations/Version20230408220140.php new file mode 100644 index 00000000..ffaafe36 --- /dev/null +++ b/migrations/Version20230408220140.php @@ -0,0 +1,31 @@ +. + */ + +namespace App\Doctrine\Types; + +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Type; + +/** + * A type to use for tinyint columns in MySQL + */ +class TinyIntType extends Type +{ + + public function getSQLDeclaration(array $column, AbstractPlatform $platform) + { + return 'TINYINT'; + } + + public function getName() + { + return 'tinyint'; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform) + { + //We use the comment, so that doctrine migrations can properly detect, that nothing has changed and no migration is needed. + return true; + } +} \ No newline at end of file diff --git a/src/Entity/LogSystem/AbstractLogEntry.php b/src/Entity/LogSystem/AbstractLogEntry.php index 5b6a728b..13906da3 100644 --- a/src/Entity/LogSystem/AbstractLogEntry.php +++ b/src/Entity/LogSystem/AbstractLogEntry.php @@ -160,7 +160,7 @@ abstract class AbstractLogEntry extends AbstractDBElement protected ?DateTime $timestamp = null; /** @var int The priority level of the associated level. 0 is highest, 7 lowest - * @ORM\Column(type="integer", name="level", columnDefinition="TINYINT(4) NOT NULL") + * @ORM\Column(type="tinyint", name="level", nullable=false) */ protected int $level;