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,
"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 ("FORM", "Standard Form");
INSERT INTO "Ref_Template_Types" VALUES ("REPORT", "Analytical Report");
INSERT INTO "Ref_Template_Types" VALUES ("LETTER", "Official Letter");
INSERT INTO "Ref_Template_Types" VALUES ("MEMO", "Internal Memorandum");
INSERT INTO "Ref_Template_Types" VALUES ("POLICY", "Company Policy Document");
INSERT INTO "Templates" VALUES ("101", "1", "FORM");
INSERT INTO "Templates" VALUES ("102", "2", "REPORT");
INSERT INTO "Templates" VALUES ("103", "1", "LETTER");
INSERT INTO "Templates" VALUES ("104", "3", "FORM");
INSERT INTO "Templates" VALUES ("105", "1", "MEMO");
INSERT INTO "Templates" VALUES ("106", "2", "LETTER");
INSERT INTO "Templates" VALUES ("107", "4", "REPORT");
INSERT INTO "Templates" VALUES ("108", "1", "POLICY");
INSERT INTO "Templates" VALUES ("109", "5", "FORM");
INSERT INTO "Templates" VALUES ("110", "2", "POLICY");
INSERT INTO "Documents" VALUES ("1", "101", "Application Form v1");
INSERT INTO "Documents" VALUES ("2", "102", "Sales Report Q1 v2");
INSERT INTO "Documents" VALUES ("3", "103", "Welcome Letter v1");
INSERT INTO "Documents" VALUES ("4", "104", "Feedback Form v3");
INSERT INTO "Documents" VALUES ("5", "105", "Meeting Minutes v1");
INSERT INTO "Documents" VALUES ("6", "106", "Confirmation Letter v2");
INSERT INTO "Documents" VALUES ("7", "107", "Financial Report 2023 v4");
INSERT INTO "Documents" VALUES ("8", "108", "Privacy Policy v1");
INSERT INTO "Documents" VALUES ("9", "109", "Survey Form v5");
INSERT INTO "Documents" VALUES ("10", "110", "Security Policy v2");
INSERT INTO "Documents" VALUES ("11", "101", "Order Form v1");
INSERT INTO "Documents" VALUES ("12", "103", "Invoice Letter v1");