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,
"Document_Name" VARCHAR(255),
PRIMARY KEY ("Document_ID"),
FOREIGN KEY ("Template_ID") REFERENCES "Templates"("Template_ID")
);

CREATE TABLE "Paragraphs" (
"Paragraph_ID" INT,
"Paragraph_Text" VARCHAR(255),
PRIMARY KEY ("Paragraph_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 ("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", "INV");
INSERT INTO "Templates" VALUES ("102", "REP");
INSERT INTO "Templates" VALUES ("103", "LTR");
INSERT INTO "Templates" VALUES ("104", "MEM");
INSERT INTO "Templates" VALUES ("105", "AGR");
INSERT INTO "Templates" VALUES ("106", "INV");
INSERT INTO "Templates" VALUES ("107", "REP");
INSERT INTO "Documents" VALUES ("1", "101", "Invoice_001");
INSERT INTO "Documents" VALUES ("2", "101", "Invoice_002");
INSERT INTO "Documents" VALUES ("3", "102", "Report_Q1");
INSERT INTO "Documents" VALUES ("4", "103", "Letter_ClientA");
INSERT INTO "Documents" VALUES ("5", "101", "Invoice_003");
INSERT INTO "Documents" VALUES ("6", "104", "Memo_Meeting");
INSERT INTO "Documents" VALUES ("7", "102", "Report_Q2");
INSERT INTO "Documents" VALUES ("8", "101", "Invoice_004");
INSERT INTO "Documents" VALUES ("9", "105", "Agreement_V1");
INSERT INTO "Documents" VALUES ("10", "103", "Letter_ClientB");
INSERT INTO "Documents" VALUES ("11", "101", "Invoice_005");
INSERT INTO "Documents" VALUES ("12", "102", "Report_Annual");
INSERT INTO "Documents" VALUES ("13", "104", "Memo_ProjectX");
INSERT INTO "Documents" VALUES ("14", "101", "Invoice_006");
INSERT INTO "Documents" VALUES ("15", "106", "Invoice_007");
INSERT INTO "Documents" VALUES ("16", "106", "Invoice_008");
INSERT INTO "Documents" VALUES ("17", "107", "Report_Sales");
INSERT INTO "Paragraphs" VALUES ("1", "This is the first paragraph of the document.");
INSERT INTO "Paragraphs" VALUES ("2", "Second paragraph with some more details.");
INSERT INTO "Paragraphs" VALUES ("3", "A concluding paragraph for the document.");
INSERT INTO "Paragraphs" VALUES ("4", "Important note regarding the terms and conditions.");
INSERT INTO "Paragraphs" VALUES ("5", "Summary of the key findings in the report.");