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,
"Document_Name" VARCHAR(255),
PRIMARY KEY ("Document_ID"),
FOREIGN KEY ("Template_ID") REFERENCES "Templates"("Template_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,
"Version_Number" INT,
"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 ("MEM", "Memorandum Template");
INSERT INTO "Ref_Template_Types" VALUES ("AGR", "Agreement Template");
INSERT INTO "Ref_Template_Types" VALUES ("LTR", "Letter Template");
INSERT INTO "Ref_Template_Types" VALUES ("FOR", "Form Template");
INSERT INTO "Templates" VALUES ("1", "1", "INV");
INSERT INTO "Templates" VALUES ("2", "6", "INV");
INSERT INTO "Templates" VALUES ("3", "3", "REP");
INSERT INTO "Templates" VALUES ("4", "7", "REP");
INSERT INTO "Templates" VALUES ("5", "5", "MEM");
INSERT INTO "Templates" VALUES ("6", "8", "MEM");
INSERT INTO "Templates" VALUES ("7", "2", "AGR");
INSERT INTO "Templates" VALUES ("8", "9", "AGR");
INSERT INTO "Templates" VALUES ("9", "4", "LTR");
INSERT INTO "Templates" VALUES ("10", "10", "LTR");
INSERT INTO "Templates" VALUES ("11", "1", "FOR");
INSERT INTO "Templates" VALUES ("12", "6", "FOR");
INSERT INTO "Documents" VALUES ("101", "1", "Invoice_2023_001");
INSERT INTO "Documents" VALUES ("102", "2", "Invoice_2023_002");
INSERT INTO "Documents" VALUES ("103", "3", "Monthly_Report_Jan");
INSERT INTO "Documents" VALUES ("104", "4", "Monthly_Report_Feb");
INSERT INTO "Documents" VALUES ("105", "5", "Internal_Memo_Q1");
INSERT INTO "Documents" VALUES ("106", "6", "Internal_Memo_Q2");
INSERT INTO "Documents" VALUES ("107", "7", "Service_Agreement_A");
INSERT INTO "Documents" VALUES ("108", "8", "Service_Agreement_B");
INSERT INTO "Documents" VALUES ("109", "9", "Client_Letter_1");
INSERT INTO "Documents" VALUES ("110", "10", "Client_Letter_2");
INSERT INTO "Documents" VALUES ("111", "11", "Application_Form_001");
INSERT INTO "Documents" VALUES ("112", "12", "Application_Form_002");
INSERT INTO "Documents" VALUES ("113", "2", "Invoice_2023_003");
INSERT INTO "Documents" VALUES ("114", "4", "Annual_Report_2022");
INSERT INTO "Documents" VALUES ("115", "6", "Policy_Update_Memo");
INSERT INTO "Documents" VALUES ("116", "8", "Partnership_Agreement");
INSERT INTO "Documents" VALUES ("117", "10", "Follow_Up_Letter");