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) 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),
PRIMARY KEY ("Template_ID"),
FOREIGN KEY ("Template_Type_Code") REFERENCES "Ref_Template_Types"("Template_Type_Code")
);





INSERT INTO "Ref_Template_Types" VALUES ("TYPE_A", "Type A Description");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B", "Type B Description");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C", "Type C Description");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D", "Type D Description");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E", "Type E Description");
INSERT INTO "Templates" VALUES ("1", "1", "TYPE_A");
INSERT INTO "Templates" VALUES ("2", "2", "TYPE_B");
INSERT INTO "Templates" VALUES ("3", "1", "TYPE_C");
INSERT INTO "Templates" VALUES ("4", "3", "TYPE_A");
INSERT INTO "Templates" VALUES ("5", "1", "TYPE_D");
INSERT INTO "Documents" VALUES ("101", "1", "Document 1");
INSERT INTO "Documents" VALUES ("102", "2", "Document 2");
INSERT INTO "Documents" VALUES ("103", "4", "Document 3");
INSERT INTO "Documents" VALUES ("104", "5", "Document 4");