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,
"Template_Details" VARCHAR(255),
PRIMARY KEY ("Template_ID")
);





INSERT INTO "Ref_Template_Types" VALUES ("INV", "Invoice Template");
INSERT INTO "Ref_Template_Types" VALUES ("REP", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("LTR", "Letter Template");
INSERT INTO "Ref_Template_Types" VALUES ("MEM", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("AGR", "Agreement Template");
INSERT INTO "Templates" VALUES ("101", "Standard Invoice Template v1.0");
INSERT INTO "Templates" VALUES ("102", "Monthly Sales Report Template");
INSERT INTO "Templates" VALUES ("103", "Client Welcome Letter Template");
INSERT INTO "Templates" VALUES ("104", "Internal Memo Template");
INSERT INTO "Templates" VALUES ("105", "Service Agreement Template");
INSERT INTO "Templates" VALUES ("106", "Project Proposal Template");
INSERT INTO "Templates" VALUES ("107", "Meeting Minutes Template");
INSERT INTO "Documents" VALUES ("1", "101");
INSERT INTO "Documents" VALUES ("2", "101");
INSERT INTO "Documents" VALUES ("3", "102");
INSERT INTO "Documents" VALUES ("4", "103");
INSERT INTO "Documents" VALUES ("5", "104");
INSERT INTO "Documents" VALUES ("6", "105");
INSERT INTO "Documents" VALUES ("7", "101");
INSERT INTO "Documents" VALUES ("8", "102");
INSERT INTO "Documents" VALUES ("9", "106");
INSERT INTO "Documents" VALUES ("10", "107");
INSERT INTO "Documents" VALUES ("11", "103");
INSERT INTO "Documents" VALUES ("12", "104");
INSERT INTO "Paragraphs" VALUES ("1001", "1");
INSERT INTO "Paragraphs" VALUES ("1002", "1");
INSERT INTO "Paragraphs" VALUES ("1003", "2");
INSERT INTO "Paragraphs" VALUES ("1004", "3");
INSERT INTO "Paragraphs" VALUES ("1005", "3");
INSERT INTO "Paragraphs" VALUES ("1006", "3");
INSERT INTO "Paragraphs" VALUES ("1007", "4");
INSERT INTO "Paragraphs" VALUES ("1008", "5");
INSERT INTO "Paragraphs" VALUES ("1009", "6");
INSERT INTO "Paragraphs" VALUES ("1010", "7");
INSERT INTO "Paragraphs" VALUES ("1011", "8");
INSERT INTO "Paragraphs" VALUES ("1012", "9");
INSERT INTO "Paragraphs" VALUES ("1013", "10");
INSERT INTO "Paragraphs" VALUES ("1014", "11");
INSERT INTO "Paragraphs" VALUES ("1015", "12");
INSERT INTO "Paragraphs" VALUES ("1016", "1");
INSERT INTO "Paragraphs" VALUES ("1017", "2");
INSERT INTO "Paragraphs" VALUES ("1018", "4");
INSERT INTO "Paragraphs" VALUES ("1019", "5");
INSERT INTO "Paragraphs" VALUES ("1020", "6");