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 UNIQUE,
"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 ("ORD", "Order Form Template");
INSERT INTO "Ref_Template_Types" VALUES ("RPT", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("LTR", "Letter Template");
INSERT INTO "Ref_Template_Types" VALUES ("MEM", "Memo Template");
INSERT INTO "Templates" VALUES ("101", "1", "INV");
INSERT INTO "Templates" VALUES ("102", "2", "ORD");
INSERT INTO "Templates" VALUES ("103", "1", "RPT");
INSERT INTO "Templates" VALUES ("104", "3", "INV");
INSERT INTO "Templates" VALUES ("105", "1", "LTR");
INSERT INTO "Templates" VALUES ("106", "2", "RPT");
INSERT INTO "Templates" VALUES ("107", "1", "MEM");
INSERT INTO "Templates" VALUES ("108", "4", "INV");
INSERT INTO "Documents" VALUES ("1", "101", "Invoice_2023_001");
INSERT INTO "Documents" VALUES ("2", "102", "Order_2023_005");
INSERT INTO "Documents" VALUES ("3", "103", "Monthly_Sales_Report");
INSERT INTO "Documents" VALUES ("4", "101", "Invoice_2023_002");
INSERT INTO "Documents" VALUES ("5", "104", "Invoice_2023_003_v3");
INSERT INTO "Documents" VALUES ("6", "105", "Client_Welcome_Letter");
INSERT INTO "Documents" VALUES ("7", "106", "Quarterly_Financial_Report");
INSERT INTO "Documents" VALUES ("8", "107", "Internal_Meeting_Memo");
INSERT INTO "Documents" VALUES ("9", "108", "Invoice_2023_004_v4");
INSERT INTO "Documents" VALUES ("10", "102", "Order_2023_006");