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 ("REP", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("MEM", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("AGR", "Agreement Template");
INSERT INTO "Ref_Template_Types" VALUES ("PRO", "Proposal Template");
INSERT INTO "Templates" VALUES ("101", "1", "INV");
INSERT INTO "Templates" VALUES ("102", "2", "INV");
INSERT INTO "Templates" VALUES ("201", "1", "ORD");
INSERT INTO "Templates" VALUES ("202", "3", "ORD");
INSERT INTO "Templates" VALUES ("301", "1", "REP");
INSERT INTO "Templates" VALUES ("302", "2", "REP");
INSERT INTO "Templates" VALUES ("401", "1", "MEM");
INSERT INTO "Templates" VALUES ("501", "1", "AGR");
INSERT INTO "Templates" VALUES ("601", "1", "PRO");
INSERT INTO "Templates" VALUES ("602", "2", "PRO");
INSERT INTO "Documents" VALUES ("1", "101", "Invoice_001");
INSERT INTO "Documents" VALUES ("2", "101", "Invoice_002");
INSERT INTO "Documents" VALUES ("3", "102", "Invoice_003_v2");
INSERT INTO "Documents" VALUES ("4", "201", "Order_Form_A");
INSERT INTO "Documents" VALUES ("5", "202", "Order_Form_B_v3");
INSERT INTO "Documents" VALUES ("6", "301", "Monthly_Report");
INSERT INTO "Documents" VALUES ("7", "302", "Annual_Report_v2");
INSERT INTO "Documents" VALUES ("8", "401", "Internal_Memo");
INSERT INTO "Documents" VALUES ("9", "501", "Service_Agreement");
INSERT INTO "Documents" VALUES ("10", "601", "Project_Proposal");
INSERT INTO "Documents" VALUES ("11", "602", "Revised_Proposal");
INSERT INTO "Documents" VALUES ("12", "101", "Invoice_004");
INSERT INTO "Documents" VALUES ("13", "201", "Order_Form_C");