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 ("MEMO", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("FORM", "Form Template");
INSERT INTO "Ref_Template_Types" VALUES ("AGR", "Agreement Template");
INSERT INTO "Ref_Template_Types" VALUES ("PRES", "Presentation Template");
INSERT INTO "Templates" VALUES ("101", "3", "INV");
INSERT INTO "Templates" VALUES ("102", "7", "REP");
INSERT INTO "Templates" VALUES ("103", "1", "MEMO");
INSERT INTO "Templates" VALUES ("104", "6", "FORM");
INSERT INTO "Templates" VALUES ("105", "9", "AGR");
INSERT INTO "Templates" VALUES ("106", "2", "INV");
INSERT INTO "Templates" VALUES ("107", "5", "REP");
INSERT INTO "Templates" VALUES ("108", "8", "MEMO");
INSERT INTO "Templates" VALUES ("109", "10", "FORM");
INSERT INTO "Templates" VALUES ("110", "4", "AGR");
INSERT INTO "Templates" VALUES ("111", "12", "PRES");
INSERT INTO "Documents" VALUES ("1", "101", "Invoice_2023_001");
INSERT INTO "Documents" VALUES ("2", "102", "Quarterly_Report_Q1");
INSERT INTO "Documents" VALUES ("3", "103", "Internal_Memo_HR");
INSERT INTO "Documents" VALUES ("4", "104", "Application_Form_V2");
INSERT INTO "Documents" VALUES ("5", "105", "Service_Agreement_ClientA");
INSERT INTO "Documents" VALUES ("6", "101", "Invoice_2023_002");
INSERT INTO "Documents" VALUES ("7", "107", "Annual_Report_2022");
INSERT INTO "Documents" VALUES ("8", "108", "Project_Update_Memo");
INSERT INTO "Documents" VALUES ("9", "109", "Feedback_Form_V3");
INSERT INTO "Documents" VALUES ("10", "110", "Partnership_Agreement_B");
INSERT INTO "Documents" VALUES ("11", "102", "Monthly_Sales_Report");
INSERT INTO "Documents" VALUES ("12", "104", "Onboarding_Form");
INSERT INTO "Documents" VALUES ("13", "105", "NDA_Agreement");
INSERT INTO "Documents" VALUES ("14", "111", "Q3_Presentation");