PRAGMA foreign_keys = ON;

PRAGMA writable_schema = 1;
DELETE FROM sqlite_master WHERE type IN ("table", "index", "trigger");
PRAGMA writable_schema = 0;
VACUUM;

CREATE TABLE "Documents" (
"Document_ID" INT UNIQUE,
"Template_ID" INT,
PRIMARY KEY ("Document_ID"),
FOREIGN KEY ("Template_ID") REFERENCES "Templates"("Template_ID")
);

CREATE TABLE "Paragraphs" (
"Paragraph_ID" INT,
"Document_ID" INT,
PRIMARY KEY ("Paragraph_ID"),
FOREIGN KEY ("Document_ID") REFERENCES "Documents"("Document_ID")
);

CREATE TABLE "Ref_Template_Types" (
"Template_Type_Code" CHAR(15),
"Template_Type_Description" VARCHAR(255),
PRIMARY KEY ("Template_Type_Code")
);

CREATE TABLE "Templates" (
"Template_ID" INT UNIQUE,
"Template_Type_Code" CHAR(15),
PRIMARY KEY ("Template_ID"),
FOREIGN KEY ("Template_Type_Code") REFERENCES "Ref_Template_Types"("Template_Type_Code")
);





INSERT INTO "Ref_Template_Types" VALUES ("TYPE_A", "Legal Document");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B", "Financial Report");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C", "Technical Manual");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D", "Marketing Brochure");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E", "HR Policy");
INSERT INTO "Templates" VALUES ("101", "TYPE_A");
INSERT INTO "Templates" VALUES ("102", "TYPE_B");
INSERT INTO "Templates" VALUES ("103", "TYPE_C");
INSERT INTO "Templates" VALUES ("104", "TYPE_D");
INSERT INTO "Templates" VALUES ("105", "TYPE_E");
INSERT INTO "Documents" VALUES ("1001", "101");
INSERT INTO "Documents" VALUES ("1002", "101");
INSERT INTO "Documents" VALUES ("1003", "102");
INSERT INTO "Documents" VALUES ("1004", "103");
INSERT INTO "Documents" VALUES ("1005", "103");
INSERT INTO "Documents" VALUES ("1006", "103");
INSERT INTO "Documents" VALUES ("1007", "104");
INSERT INTO "Documents" VALUES ("1008", "105");
INSERT INTO "Documents" VALUES ("1009", "105");
INSERT INTO "Documents" VALUES ("1010", "105");
INSERT INTO "Paragraphs" VALUES ("1", "1001");
INSERT INTO "Paragraphs" VALUES ("2", "1001");
INSERT INTO "Paragraphs" VALUES ("3", "1002");
INSERT INTO "Paragraphs" VALUES ("4", "1003");
INSERT INTO "Paragraphs" VALUES ("5", "1004");
INSERT INTO "Paragraphs" VALUES ("6", "1005");
INSERT INTO "Paragraphs" VALUES ("7", "1006");
INSERT INTO "Paragraphs" VALUES ("8", "1007");
INSERT INTO "Paragraphs" VALUES ("9", "1008");
INSERT INTO "Paragraphs" VALUES ("10", "1009");
INSERT INTO "Paragraphs" VALUES ("11", "1010");
INSERT INTO "Paragraphs" VALUES ("12", "1010");