From 61e6e61b8b944261984095bbc5f337a55e137655 Mon Sep 17 00:00:00 2001 From: team2 Date: Sat, 21 Feb 2026 19:23:38 +0100 Subject: [PATCH] fix maigrations --- migrations/Version20260221000100.php | 86 +++++++++++----------------- migrations/Version20260221000300.php | 40 +++++++++++++ 2 files changed, 74 insertions(+), 52 deletions(-) create mode 100644 migrations/Version20260221000300.php diff --git a/migrations/Version20260221000100.php b/migrations/Version20260221000100.php index 8cdff04..55818a1 100644 --- a/migrations/Version20260221000100.php +++ b/migrations/Version20260221000100.php @@ -11,71 +11,53 @@ final class Version20260221000100 extends AbstractMigration { public function getDescription(): string { - return 'Adds tagging system for DocumentVersion (Tag + document_version_tag)'; + return 'Creates knowledge_tag and document_tag tables (MariaDB compatible)'; } public function up(Schema $schema): void { - // -------------------------------------------------- - // TAG TABLE - // -------------------------------------------------- - + // KNOWLEDGE_TAG TABLE (matches Tag entity) $this->addSql(" - CREATE TABLE tag ( - id UUID NOT NULL, - name VARCHAR(120) NOT NULL, + CREATE TABLE knowledge_tag ( + id BINARY(16) NOT NULL, slug VARCHAR(120) NOT NULL, - created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, - PRIMARY KEY(id) - ) + label VARCHAR(180) NOT NULL, + description TEXT DEFAULT NULL, + created_at DATETIME NOT NULL, + PRIMARY KEY(id), + UNIQUE INDEX uniq_knowledge_tag_slug (slug), + INDEX idx_knowledge_tag_slug (slug), + INDEX idx_knowledge_tag_label (label) + ) ENGINE=InnoDB + DEFAULT CHARSET=utf8mb4 + COLLATE=utf8mb4_unicode_ci "); + // DOCUMENT_TAG TABLE $this->addSql(" - CREATE UNIQUE INDEX uniq_tag_slug ON tag (slug) - "); - - // -------------------------------------------------- - // DOCUMENT_VERSION_TAG (ManyToMany) - // -------------------------------------------------- - - $this->addSql(" - CREATE TABLE document_version_tag ( - document_version_id UUID NOT NULL, - tag_id UUID NOT NULL, - PRIMARY KEY(document_version_id, tag_id) - ) - "); - - $this->addSql(" - CREATE INDEX idx_dv_tag_version - ON document_version_tag (document_version_id) - "); - - $this->addSql(" - CREATE INDEX idx_dv_tag_tag - ON document_version_tag (tag_id) - "); - - $this->addSql(" - ALTER TABLE document_version_tag - ADD CONSTRAINT fk_dv_tag_version - FOREIGN KEY (document_version_id) - REFERENCES document_version (id) - ON DELETE CASCADE - "); - - $this->addSql(" - ALTER TABLE document_version_tag - ADD CONSTRAINT fk_dv_tag_tag - FOREIGN KEY (tag_id) - REFERENCES tag (id) - ON DELETE CASCADE + CREATE TABLE document_tag ( + document_id BINARY(16) NOT NULL, + tag_id BINARY(16) NOT NULL, + PRIMARY KEY(document_id, tag_id), + KEY IDX_DOCUMENT_TAG_DOCUMENT (document_id), + KEY IDX_DOCUMENT_TAG_TAG (tag_id), + CONSTRAINT FK_DOCUMENT_TAG_DOCUMENT + FOREIGN KEY (document_id) + REFERENCES document (id) + ON DELETE CASCADE, + CONSTRAINT FK_DOCUMENT_TAG_TAG + FOREIGN KEY (tag_id) + REFERENCES knowledge_tag (id) + ON DELETE CASCADE + ) ENGINE=InnoDB + DEFAULT CHARSET=utf8mb4 + COLLATE=utf8mb4_unicode_ci "); } public function down(Schema $schema): void { - $this->addSql("DROP TABLE document_version_tag"); - $this->addSql("DROP TABLE tag"); + $this->addSql("DROP TABLE document_tag"); + $this->addSql("DROP TABLE knowledge_tag"); } } \ No newline at end of file diff --git a/migrations/Version20260221000300.php b/migrations/Version20260221000300.php new file mode 100644 index 0000000..5bf5d61 --- /dev/null +++ b/migrations/Version20260221000300.php @@ -0,0 +1,40 @@ +addSql(" + CREATE TABLE tag_rebuild_job ( + id BINARY(16) NOT NULL, + status VARCHAR(16) NOT NULL, + created_at DATETIME NOT NULL, + started_at DATETIME DEFAULT NULL, + finished_at DATETIME DEFAULT NULL, + error_message TEXT DEFAULT NULL, + PRIMARY KEY(id), + INDEX idx_tag_rebuild_job_status (status), + INDEX idx_tag_rebuild_job_created_at (created_at) + ) ENGINE=InnoDB + DEFAULT CHARSET=utf8mb4 + COLLATE=utf8mb4_unicode_ci + "); + } + + public function down(Schema $schema): void + { + $this->addSql("DROP TABLE tag_rebuild_job"); + } +} \ No newline at end of file