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,
"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 ("TYPE_A", "Invoice Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C", "Contract Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E", "Newsletter Template");
INSERT INTO "Templates" VALUES ("101", "TYPE_A");
INSERT INTO "Templates" VALUES ("102", "TYPE_B");
INSERT INTO "Templates" VALUES ("103", "TYPE_C");
INSERT INTO "Templates" VALUES ("104", "TYPE_D");
INSERT INTO "Templates" VALUES ("105", "TYPE_E");
INSERT INTO "Templates" VALUES ("106", "TYPE_A");
INSERT INTO "Templates" VALUES ("107", "TYPE_B");
INSERT INTO "Templates" VALUES ("108", "TYPE_C");
INSERT INTO "Documents" VALUES ("201", "101", "Invoice Jan 2024");
INSERT INTO "Documents" VALUES ("202", "102", "Annual Report 2023");
INSERT INTO "Documents" VALUES ("203", "101", "Invoice Feb 2024");
INSERT INTO "Documents" VALUES ("204", "103", "Contract with Vendor A");
INSERT INTO "Documents" VALUES ("205", "103", "Contract with Vendor B");
INSERT INTO "Documents" VALUES ("206", "107", "Monthly Report March");
INSERT INTO "Documents" VALUES ("207", "107", "Monthly Report April");