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_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 ("1", "Standard Invoice Template");
INSERT INTO "Templates" VALUES ("2", "Monthly Sales Report");
INSERT INTO "Templates" VALUES ("3", "Client Welcome Letter");
INSERT INTO "Templates" VALUES ("4", "Internal Memo");
INSERT INTO "Templates" VALUES ("5", "Service Agreement");
INSERT INTO "Templates" VALUES ("6", "Unused Template");
INSERT INTO "Templates" VALUES ("7", "Another Unused Template");
INSERT INTO "Templates" VALUES ("8", "Project Proposal");
INSERT INTO "Documents" VALUES ("101", "1", "Invoice_2023_001");
INSERT INTO "Documents" VALUES ("102", "2", "Sales_Report_Q1_2023");
INSERT INTO "Documents" VALUES ("103", "3", "Welcome_Letter_Client_A");
INSERT INTO "Documents" VALUES ("104", "1", "Invoice_2023_002");
INSERT INTO "Documents" VALUES ("105", "4", "Meeting_Minutes_05_10_2023");
INSERT INTO "Documents" VALUES ("106", "5", "Client_B_Service_Agreement");
INSERT INTO "Documents" VALUES ("107", "2", "Sales_Report_Q2_2023");
INSERT INTO "Documents" VALUES ("108", "8", "Project_X_Proposal");