﻿START TRANSACTION;
DROP TABLE "Dictionaries";

CREATE TABLE "DictItems" (
    "Uuid" uuid NOT NULL,
    parentid uuid,
    parentvalue text,
    label character varying(100) NOT NULL,
    "LabelEn" character varying(100),
    "Remark" character varying(500),
    value character varying(50) NOT NULL,
    tag character varying(500),
    createtime timestamp with time zone NOT NULL,
    "CreateUserId" uuid NOT NULL,
    CONSTRAINT "PK_DictItems" PRIMARY KEY ("Uuid"),
    CONSTRAINT "CK_TopLevelItems" CHECK (ParentId IS NULL OR (Tag IS NOT NULL AND ParentValue IS NOT NULL)),
    CONSTRAINT "FK_DictItems_DictItems_parentid" FOREIGN KEY (parentid) REFERENCES "DictItems" ("Uuid") ON DELETE CASCADE
);

CREATE INDEX "IX_DictItems_parentid" ON "DictItems" (parentid);

CREATE INDEX "IX_DictItems_parentvalue" ON "DictItems" (parentvalue);

CREATE INDEX "IX_DictItems_tag" ON "DictItems" (tag);

CREATE INDEX "IX_DictItems_value" ON "DictItems" (value);

INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20250715135627_dic1', '9.0.6');

COMMIT;

