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 ("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 "Ref_Template_Types" VALUES ("REC", "Receipt Template");
INSERT INTO "Templates" VALUES ("101", "1", "INV", "Standard Invoice v1.0");
INSERT INTO "Templates" VALUES ("102", "2", "INV", "Standard Invoice v2.0 with tax fields");
INSERT INTO "Templates" VALUES ("103", "1", "ORD", "Basic Order Form");
INSERT INTO "Templates" VALUES ("104", "1", "REP", "Monthly Sales Report");
INSERT INTO "Templates" VALUES ("105", "1", "MEM", "Internal Memo Template");
INSERT INTO "Templates" VALUES ("106", "1", "AGR", "Service Agreement Draft");
INSERT INTO "Templates" VALUES ("107", "1", "INV", "Invoice Template for Services");
INSERT INTO "Templates" VALUES ("108", "3", "INV", "Standard Invoice v3.0 with discount options");
INSERT INTO "Templates" VALUES ("109", "2", "ORD", "Detailed Order Form with shipping");
INSERT INTO "Templates" VALUES ("110", "1", "PRO", "Project Proposal Template");
INSERT INTO "Templates" VALUES ("111", "1", "REC", "Simple Receipt Template");
INSERT INTO "Templates" VALUES ("112", "2", "REP", "Quarterly Financial Report");
INSERT INTO "Templates" VALUES ("113", "1", "AGR", "Non-Disclosure Agreement");
INSERT INTO "Templates" VALUES ("114", "1", "INV", "Invoice Template for Products");
INSERT INTO "Documents" VALUES ("1", "101");
INSERT INTO "Documents" VALUES ("2", "102");
INSERT INTO "Documents" VALUES ("3", "103");
INSERT INTO "Documents" VALUES ("4", "104");
INSERT INTO "Documents" VALUES ("5", "105");
INSERT INTO "Documents" VALUES ("6", "106");
INSERT INTO "Documents" VALUES ("7", "107");
INSERT INTO "Documents" VALUES ("8", "108");
INSERT INTO "Documents" VALUES ("9", "109");
INSERT INTO "Documents" VALUES ("10", "110");
INSERT INTO "Documents" VALUES ("11", "111");
INSERT INTO "Documents" VALUES ("12", "112");
INSERT INTO "Documents" VALUES ("13", "113");
INSERT INTO "Documents" VALUES ("14", "114");
INSERT INTO "Documents" VALUES ("15", "101");
INSERT INTO "Documents" VALUES ("16", "102");
INSERT INTO "Documents" VALUES ("17", "103");
INSERT INTO "Documents" VALUES ("18", "104");
INSERT INTO "Documents" VALUES ("19", "107");
INSERT INTO "Documents" VALUES ("20", "108");