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),
"Template_Type_Description" VARCHAR(255),
PRIMARY KEY ("Template_Type_Code")
);

CREATE TABLE "Templates" (
"Template_ID" INT,
"Version_Number" INT,
"Template_Type_Code" CHAR(15),
"Date_Effective_From" DATETIME,
PRIMARY KEY ("Template_ID"),
FOREIGN KEY ("Template_Type_Code") REFERENCES "Ref_Template_Types"("Template_Type_Code")
);





INSERT INTO "Ref_Template_Types" VALUES ("TYPE_A", "Contract Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B", "Invoice Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D", "Memo Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E", "Policy Template");
INSERT INTO "Templates" VALUES ("1", "5", "TYPE_A", "2023-01-01 00:00:00");
INSERT INTO "Templates" VALUES ("2", "3", "TYPE_A", "2022-06-15 00:00:00");
INSERT INTO "Templates" VALUES ("3", "1", "TYPE_B", "2021-12-01 00:00:00");
INSERT INTO "Templates" VALUES ("4", "2", "TYPE_B", "2022-01-10 00:00:00");
INSERT INTO "Templates" VALUES ("5", "4", "TYPE_C", "2023-03-20 00:00:00");
INSERT INTO "Templates" VALUES ("6", "1", "TYPE_D", "2020-05-05 00:00:00");
INSERT INTO "Templates" VALUES ("7", "7", "TYPE_E", "2023-07-01 00:00:00");
INSERT INTO "Templates" VALUES ("8", "1", "TYPE_E", "2021-08-08 00:00:00");
INSERT INTO "Documents" VALUES ("100", "1");
INSERT INTO "Documents" VALUES ("101", "2");
INSERT INTO "Documents" VALUES ("102", "3");
INSERT INTO "Documents" VALUES ("103", "4");
INSERT INTO "Documents" VALUES ("104", "5");
INSERT INTO "Documents" VALUES ("105", "6");
INSERT INTO "Documents" VALUES ("106", "7");
INSERT INTO "Documents" VALUES ("107", "8");
INSERT INTO "Documents" VALUES ("108", "3");
INSERT INTO "Documents" VALUES ("109", "6");