add tagging
This commit is contained in:
81
migrations/Version20260221000100.php
Normal file
81
migrations/Version20260221000100.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260221000100 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Adds tagging system for DocumentVersion (Tag + document_version_tag)';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// --------------------------------------------------
|
||||
// TAG TABLE
|
||||
// --------------------------------------------------
|
||||
|
||||
$this->addSql("
|
||||
CREATE TABLE tag (
|
||||
id UUID NOT NULL,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
slug VARCHAR(120) NOT NULL,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
PRIMARY KEY(id)
|
||||
)
|
||||
");
|
||||
|
||||
$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
|
||||
");
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql("DROP TABLE document_version_tag");
|
||||
$this->addSql("DROP TABLE tag");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user