CREATE TABLE tag (
    id INT AUTO_INCREMENT NOT NULL,
    name VARCHAR(190) NOT NULL,
    UNIQUE INDEX UNIQ_389B7835E237E06 (name),
    PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB;
CREATE TABLE tagging (
    id INT AUTO_INCREMENT NOT NULL,
    tag_id INT DEFAULT NULL,
    resource_id INT DEFAULT NULL,
    owner_id INT DEFAULT NULL,
    status VARCHAR(190) NOT NULL,
    created DATETIME NOT NULL,
    modified DATETIME DEFAULT NULL,
    INDEX IDX_A4AED123BAD26311 (tag_id),
    INDEX IDX_A4AED12389329D25 (resource_id),
    INDEX IDX_A4AED1237E3C61F9 (owner_id),
    INDEX IDX_A4AED1237B00651C (status),
    UNIQUE INDEX owner_tag_resource (owner_id, tag_id, resource_id),
    PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB;
ALTER TABLE tagging ADD CONSTRAINT FK_A4AED123BAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id) ON DELETE SET NULL;
ALTER TABLE tagging ADD CONSTRAINT FK_A4AED12389329D25 FOREIGN KEY (resource_id) REFERENCES resource (id) ON DELETE SET NULL;
ALTER TABLE tagging ADD CONSTRAINT FK_A4AED1237E3C61F9 FOREIGN KEY (owner_id) REFERENCES user (id) ON DELETE SET NULL;
