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,
"Version_Number" INT,
"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 ("CV", "Curriculum Vitae");
INSERT INTO "Ref_Template_Types" VALUES ("Letter", "Formal Letter");
INSERT INTO "Ref_Template_Types" VALUES ("Report", "Project Report");
INSERT INTO "Ref_Template_Types" VALUES ("Invoice", "Billing Invoice");
INSERT INTO "Ref_Template_Types" VALUES ("Memo", "Internal Memorandum");
INSERT INTO "Ref_Template_Types" VALUES ("CV_Old", "Old Curriculum Vitae");
INSERT INTO "Templates" VALUES ("1", "1", "CV", "Standard CV Template");
INSERT INTO "Templates" VALUES ("2", "2", "CV", "Modern CV Template");
INSERT INTO "Templates" VALUES ("3", "1", "Letter", "Business Letter Template");
INSERT INTO "Templates" VALUES ("4", "1", "Report", "Annual Report Template");
INSERT INTO "Templates" VALUES ("5", "1", "CV", "Creative CV Template");
INSERT INTO "Templates" VALUES ("6", "1", "Invoice", "Service Invoice Template");
INSERT INTO "Templates" VALUES ("7", "1", "Memo", "Meeting Memo Template");
INSERT INTO "Templates" VALUES ("8", "3", "CV", "Academic CV Template");
INSERT INTO "Templates" VALUES ("9", "1", "Letter", "Personal Letter Template");
INSERT INTO "Templates" VALUES ("10", "1", "CV_Old", "Archived CV Template");
INSERT INTO "Documents" VALUES ("101", "1");
INSERT INTO "Documents" VALUES ("102", "2");
INSERT INTO "Documents" VALUES ("103", "3");
INSERT INTO "Documents" VALUES ("104", "5");
INSERT INTO "Documents" VALUES ("105", "8");
INSERT INTO "Documents" VALUES ("106", "4");
INSERT INTO "Documents" VALUES ("107", "6");
INSERT INTO "Documents" VALUES ("108", "7");
INSERT INTO "Documents" VALUES ("109", "9");
INSERT INTO "Documents" VALUES ("110", "10");