|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2026 SURFnet B.V. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +declare(strict_types=1); |
| 20 | + |
| 21 | +namespace OpenConext\EngineBlock\Doctrine\Migrations; |
| 22 | + |
| 23 | +use Doctrine\DBAL\Platforms\MariaDBPlatform; |
| 24 | +use Doctrine\DBAL\Platforms\MySQLPlatform; |
| 25 | +use Doctrine\DBAL\Schema\Schema; |
| 26 | +use Doctrine\Migrations\AbstractMigration; |
| 27 | + |
| 28 | +/** |
| 29 | + * Base class for all EngineBlock Doctrine migrations. |
| 30 | + * |
| 31 | + * All migrations in this project target MariaDB exclusively. The generated DDL SQL is platform-specific |
| 32 | + * and is not guaranteed to be compatible with MySQL or any other database engine. |
| 33 | + * |
| 34 | + */ |
| 35 | +abstract class AbstractEngineBlockMigration extends AbstractMigration |
| 36 | +{ |
| 37 | + public function preUp(Schema $schema): void |
| 38 | + { |
| 39 | + $this->checkPlatform(); |
| 40 | + } |
| 41 | + |
| 42 | + public function preDown(Schema $schema): void |
| 43 | + { |
| 44 | + $this->checkPlatform(); |
| 45 | + } |
| 46 | + |
| 47 | + private function checkPlatform(): void |
| 48 | + { |
| 49 | + if ($this->platform instanceof MariaDBPlatform) { |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + if ($this->platform instanceof MySQLPlatform) { |
| 54 | + $this->warnIf( |
| 55 | + true, |
| 56 | + sprintf( |
| 57 | + 'This migration is built for MariaDB. The current database platform is MySQL ("%s"). ' |
| 58 | + . 'EngineBlock migrations may contain MariaDB-specific DDL that may fail. ' |
| 59 | + . 'Check manually to ensure the migrations run as expected.', |
| 60 | + get_class($this->platform), |
| 61 | + ), |
| 62 | + ); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + $this->abortIf( |
| 67 | + true, |
| 68 | + sprintf( |
| 69 | + 'This migration is built for MariaDB only. The current database platform "%s" is not supported.', |
| 70 | + get_class($this->platform), |
| 71 | + ), |
| 72 | + ); |
| 73 | + } |
| 74 | +} |
0 commit comments