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,
"Version_Number" INT,
"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 "Templates" VALUES ("1", "5", "TYPE_A", "Template details for A v5");
INSERT INTO "Templates" VALUES ("2", "3", "TYPE_B", "Template details for B v3");
INSERT INTO "Templates" VALUES ("3", "1", "TYPE_C", "Template details for C v1");
INSERT INTO "Templates" VALUES ("4", "7", "TYPE_D", "Template details for D v7");
INSERT INTO "Templates" VALUES ("5", "1", "TYPE_A", "Template details for A v1");
INSERT INTO "Documents" VALUES ("10", "1");
INSERT INTO "Documents" VALUES ("11", "2");
INSERT INTO "Documents" VALUES ("12", "3");
INSERT INTO "Documents" VALUES ("13", "4");
INSERT INTO "Documents" VALUES ("14", "5");
INSERT INTO "Paragraphs" VALUES ("100", "10");
INSERT INTO "Paragraphs" VALUES ("101", "10");
INSERT INTO "Paragraphs" VALUES ("102", "11");
INSERT INTO "Paragraphs" VALUES ("103", "12");
INSERT INTO "Paragraphs" VALUES ("104", "13");
INSERT INTO "Paragraphs" VALUES ("105", "14");