*/ protected $sm; /** @var AbstractPlatform */ protected $platform; private LoggerInterface $logger; /** @var Query[] */ private array $plannedSql = []; public function __construct(Connection $connection, LoggerInterface $logger) { $this->connection = $connection; $this->sm = $this->connection->createSchemaManager(); $this->platform = $this->connection->getDatabasePlatform(); $this->logger = $logger; } /** * Indicates the transactional mode of this migration. * * If this function returns true (default) the migration will be executed * in one transaction, otherwise non-transactional state will be used to * execute each of the migration SQLs. * * Extending class should override this function to alter the return value. */ public function isTransactional(): bool { return true; } public function getDescription(): string { return ''; } public function warnIf(bool $condition, string $message = 'Unknown Reason'): void { if (! $condition) { return; } $this->logger->warning($message, ['migration' => $this]); } /** * @throws AbortMigration */ public function abortIf(bool $condition, string $message = 'Unknown Reason'): void { if ($condition) { throw new AbortMigration($message); } } /** * @throws SkipMigration */ public function skipIf(bool $condition, string $message = 'Unknown Reason'): void { if ($condition) { throw new SkipMigration($message); } } /** * @throws MigrationException|DBALException */ public function preUp(Schema $schema): void { } /** * @throws MigrationException|DBALException */ public function postUp(Schema $schema): void { } /** * @throws MigrationException|DBALException */ public function preDown(Schema $schema): void { } /** * @throws MigrationException|DBALException */ public function postDown(Schema $schema): void { } /** * @throws MigrationException|DBALException */ abstract public function up(Schema $schema): void; /** * @throws MigrationException|DBALException */ public function down(Schema $schema): void { $this->abortIf(true, sprintf('No down() migration implemented for "%s"', static::class)); } /** * @param mixed[] $params * @param mixed[] $types */ protected function addSql( string $sql, array $params = [], array $types = [] ): void { $this->plannedSql[] = new Query($sql, $params, $types); } /** * @return Query[] */ public function getSql(): array { return $this->plannedSql; } protected function write(string $message): void { $this->logger->notice($message, ['migration' => $this]); } /** * @throws IrreversibleMigration */ protected function throwIrreversibleMigrationException(?string $message = null): void { if ($message === null) { $message = 'This migration is irreversible and cannot be reverted.'; } throw new IrreversibleMigration($message); } }