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,
"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) UNIQUE,
PRIMARY KEY ("Template_Type_Code")
);

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





INSERT INTO "Ref_Template_Types" VALUES ("TYPE_A");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E");
INSERT INTO "Templates" VALUES ("1", "TYPE_A", "Template details A1");
INSERT INTO "Templates" VALUES ("2", "TYPE_A", "Template details A2");
INSERT INTO "Templates" VALUES ("3", "TYPE_B", "Template details B1");
INSERT INTO "Templates" VALUES ("4", "TYPE_C", "Template details C1");
INSERT INTO "Templates" VALUES ("5", "TYPE_D", "Template details D1");
INSERT INTO "Templates" VALUES ("6", "TYPE_D", "Template details D2");
INSERT INTO "Templates" VALUES ("7", "TYPE_D", "Template details D3");
INSERT INTO "Templates" VALUES ("8", "TYPE_E", "Template details E1");
INSERT INTO "Documents" VALUES ("101", "1");
INSERT INTO "Documents" VALUES ("102", "2");
INSERT INTO "Documents" VALUES ("103", "3");
INSERT INTO "Documents" VALUES ("104", "4");
INSERT INTO "Documents" VALUES ("105", "5");
INSERT INTO "Documents" VALUES ("106", "6");
INSERT INTO "Documents" VALUES ("107", "7");
INSERT INTO "Documents" VALUES ("108", "8");
INSERT INTO "Paragraphs" VALUES ("1001", "101");
INSERT INTO "Paragraphs" VALUES ("1002", "101");
INSERT INTO "Paragraphs" VALUES ("1003", "102");
INSERT INTO "Paragraphs" VALUES ("1004", "103");
INSERT INTO "Paragraphs" VALUES ("1005", "104");
INSERT INTO "Paragraphs" VALUES ("1006", "105");
INSERT INTO "Paragraphs" VALUES ("1007", "106");
INSERT INTO "Paragraphs" VALUES ("1008", "107");
INSERT INTO "Paragraphs" VALUES ("1009", "108");
INSERT INTO "Paragraphs" VALUES ("1010", "108");