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,
PRIMARY KEY ("Document_ID"),
FOREIGN KEY ("Template_ID") REFERENCES "Templates"("Template_ID")
);

CREATE TABLE "Ref_Template_Types" (
"Template_Type_Code" CHAR(15) UNIQUE,
"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),
"Template_Details" VARCHAR(255),
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 ("MEM", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("LTR", "Letter 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", "Standard Invoice v1.0");
INSERT INTO "Templates" VALUES ("102", "2", "INV", "Invoice with Discount v2.0");
INSERT INTO "Templates" VALUES ("201", "1", "ORD", "Basic Order Form v1.0");
INSERT INTO "Templates" VALUES ("202", "3", "ORD", "Detailed Order Form v3.0");
INSERT INTO "Templates" VALUES ("301", "1", "RPT", "Monthly Sales Report v1.0");
INSERT INTO "Templates" VALUES ("302", "1", "RPT", "Quarterly Financial Report v1.0");
INSERT INTO "Templates" VALUES ("401", "1", "MEM", "Internal Memo v1.0");
INSERT INTO "Templates" VALUES ("501", "1", "LTR", "Business Letter v1.0");
INSERT INTO "Templates" VALUES ("601", "1", "AGR", "Service Agreement v1.0");
INSERT INTO "Templates" VALUES ("701", "1", "PRO", "Project Proposal v1.0");
INSERT INTO "Templates" VALUES ("103", "1", "INV", "Invoice for Services v1.0");
INSERT INTO "Templates" VALUES ("203", "1", "ORD", "Online Order Form v1.0");
INSERT INTO "Templates" VALUES ("303", "2", "RPT", "Annual Performance Report v2.0");
INSERT INTO "Documents" VALUES ("1", "101");
INSERT INTO "Documents" VALUES ("2", "102");
INSERT INTO "Documents" VALUES ("3", "201");
INSERT INTO "Documents" VALUES ("4", "202");
INSERT INTO "Documents" VALUES ("5", "301");
INSERT INTO "Documents" VALUES ("6", "302");
INSERT INTO "Documents" VALUES ("7", "401");
INSERT INTO "Documents" VALUES ("8", "501");
INSERT INTO "Documents" VALUES ("9", "601");
INSERT INTO "Documents" VALUES ("10", "701");
INSERT INTO "Documents" VALUES ("11", "101");
INSERT INTO "Documents" VALUES ("12", "201");
INSERT INTO "Documents" VALUES ("13", "303");
INSERT INTO "Documents" VALUES ("14", "103");
INSERT INTO "Documents" VALUES ("15", "203");