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,
"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 ("TYPE_A", "Invoice Templates");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B", "Report Templates");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C", "Contract Templates");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D", "Presentation Templates");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E", "Email Templates");
INSERT INTO "Templates" VALUES ("101", "TYPE_A", "Standard Invoice Template");
INSERT INTO "Templates" VALUES ("102", "TYPE_A", "Proforma Invoice Template");
INSERT INTO "Templates" VALUES ("103", "TYPE_B", "Annual Report Template");
INSERT INTO "Templates" VALUES ("104", "TYPE_B", "Quarterly Report Template");
INSERT INTO "Templates" VALUES ("105", "TYPE_B", "Monthly Report Template");
INSERT INTO "Templates" VALUES ("106", "TYPE_C", "Employment Contract Template");
INSERT INTO "Templates" VALUES ("107", "TYPE_C", "Sales Contract Template");
INSERT INTO "Templates" VALUES ("108", "TYPE_D", "Sales Presentation Template");
INSERT INTO "Templates" VALUES ("109", "TYPE_D", "Marketing Presentation Template");
INSERT INTO "Templates" VALUES ("110", "TYPE_E", "Customer Follow-up Email Template");
INSERT INTO "Documents" VALUES ("1001", "101");
INSERT INTO "Documents" VALUES ("1002", "101");
INSERT INTO "Documents" VALUES ("1003", "102");
INSERT INTO "Documents" VALUES ("1004", "103");
INSERT INTO "Documents" VALUES ("1005", "103");
INSERT INTO "Documents" VALUES ("1006", "103");
INSERT INTO "Documents" VALUES ("1007", "104");
INSERT INTO "Documents" VALUES ("1008", "105");
INSERT INTO "Documents" VALUES ("1009", "106");
INSERT INTO "Documents" VALUES ("1010", "107");
INSERT INTO "Documents" VALUES ("1011", "108");
INSERT INTO "Documents" VALUES ("1012", "109");
INSERT INTO "Documents" VALUES ("1013", "110");
INSERT INTO "Documents" VALUES ("1014", "110");
INSERT INTO "Documents" VALUES ("1015", "110");