diff --git a/migrations/Version20260221000300.php b/migrations/Version20260221000300.php index 5bf5d61..45bce37 100644 --- a/migrations/Version20260221000300.php +++ b/migrations/Version20260221000300.php @@ -17,7 +17,7 @@ final class Version20260221000300 extends AbstractMigration public function up(Schema $schema): void { $this->addSql(" - CREATE TABLE tag_rebuild_job ( + CREATE TABLE IF NOT EXISTS tag_rebuild_job ( id BINARY(16) NOT NULL, status VARCHAR(16) NOT NULL, created_at DATETIME NOT NULL, diff --git a/migrations/Version20260225000200.php b/migrations/Version20260225000200.php index 3ef1800..1fd3056 100644 --- a/migrations/Version20260225000200.php +++ b/migrations/Version20260225000200.php @@ -17,19 +17,51 @@ final class Version20260225000200 extends AbstractMigration public function up(Schema $schema): void { $this->addSql('ALTER TABLE knowledge_tag CHANGE description description LONGTEXT DEFAULT NULL'); - $this->addSql('ALTER TABLE knowledge_tag RENAME INDEX uniq_knowledge_tag_slug TO UNIQ_86B46255989D9B62'); + + if ($this->indexExists('knowledge_tag', 'uniq_knowledge_tag_slug')) { + $this->addSql( + 'ALTER TABLE knowledge_tag RENAME INDEX uniq_knowledge_tag_slug TO UNIQ_86B46255989D9B62' + ); + } $this->addSql('ALTER TABLE document DROP FOREIGN KEY FK_D8698A769407EE77'); $this->addSql('ALTER TABLE document ADD CONSTRAINT FK_D8698A769407EE77 FOREIGN KEY (current_version_id) REFERENCES document_version (id)'); $this->addSql('ALTER TABLE tag_rebuild_job CHANGE error_message error_message LONGTEXT DEFAULT NULL'); - $this->addSql('ALTER TABLE document_tag RENAME INDEX idx_document_tag_document TO IDX_D0234567C33F7837'); - $this->addSql('ALTER TABLE document_tag RENAME INDEX idx_document_tag_tag TO IDX_D0234567BAD26311'); + if ($this->indexExists('document_tag', 'idx_document_tag_document')) { + $this->addSql( + 'ALTER TABLE document_tag RENAME INDEX idx_document_tag_document TO IDX_D0234567C33F7837' + ); + } + + if ($this->indexExists('document_tag', 'idx_document_tag_tag')) { + $this->addSql( + 'ALTER TABLE document_tag RENAME INDEX idx_document_tag_tag TO IDX_D0234567BAD26311' + ); + } + } + + private function indexExists(string $table, string $index): bool + { + $count = (int) $this->connection->fetchOne( + << $table, + 'index' => $index, + ] + ); + + return $count > 0; } public function down(Schema $schema): void { - // Optional – in Drift-Fix-Migration meist nicht notwendig } } \ No newline at end of file