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 UNIQUE,
"Version_Number" INT,
"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", "Standard Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B", "Advanced Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C", "Legacy Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D", "Experimental Template");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E", "Deprecated Template");
INSERT INTO "Templates" VALUES ("101", "3", "TYPE_A");
INSERT INTO "Templates" VALUES ("102", "5", "TYPE_B");
INSERT INTO "Templates" VALUES ("103", "6", "TYPE_C");
INSERT INTO "Templates" VALUES ("104", "7", "TYPE_D");
INSERT INTO "Templates" VALUES ("105", "10", "TYPE_E");
INSERT INTO "Templates" VALUES ("106", "1", "TYPE_A");
INSERT INTO "Templates" VALUES ("107", "8", "TYPE_B");
INSERT INTO "Templates" VALUES ("108", "4", "TYPE_C");
INSERT INTO "Templates" VALUES ("109", "9", "TYPE_D");
INSERT INTO "Templates" VALUES ("110", "2", "TYPE_E");
INSERT INTO "Documents" VALUES ("201", "101");
INSERT INTO "Documents" VALUES ("202", "102");
INSERT INTO "Documents" VALUES ("203", "103");
INSERT INTO "Documents" VALUES ("204", "104");
INSERT INTO "Documents" VALUES ("205", "105");
INSERT INTO "Documents" VALUES ("206", "106");
INSERT INTO "Documents" VALUES ("207", "107");
INSERT INTO "Documents" VALUES ("208", "108");
INSERT INTO "Documents" VALUES ("209", "109");
INSERT INTO "Documents" VALUES ("210", "110");