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 ("201", "101");
INSERT INTO "Documents" VALUES ("202", "101");
INSERT INTO "Documents" VALUES ("203", "102");
INSERT INTO "Documents" VALUES ("204", "103");
INSERT INTO "Documents" VALUES ("205", "103");
INSERT INTO "Documents" VALUES ("206", "103");
INSERT INTO "Documents" VALUES ("207", "104");
INSERT INTO "Documents" VALUES ("208", "105");
INSERT INTO "Paragraphs" VALUES ("301", "201");
INSERT INTO "Paragraphs" VALUES ("302", "201");
INSERT INTO "Paragraphs" VALUES ("303", "202");
INSERT INTO "Paragraphs" VALUES ("304", "203");
INSERT INTO "Paragraphs" VALUES ("305", "204");
INSERT INTO "Paragraphs" VALUES ("306", "205");
INSERT INTO "Paragraphs" VALUES ("307", "206");
INSERT INTO "Paragraphs" VALUES ("308", "207");
INSERT INTO "Paragraphs" VALUES ("309", "208");
INSERT INTO "Paragraphs" VALUES ("310", "208");