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 "Paragraphs" (
"Paragraph_ID" INT,
"Paragraph_Text" VARCHAR(255),
PRIMARY KEY ("Paragraph_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 ("BK", "Book Template");
INSERT INTO "Ref_Template_Types" VALUES ("BKP", "Book Preview Template");
INSERT INTO "Ref_Template_Types" VALUES ("AR", "Article Template");
INSERT INTO "Ref_Template_Types" VALUES ("RP", "Report Template");
INSERT INTO "Templates" VALUES ("101", "1", "BK");
INSERT INTO "Templates" VALUES ("102", "2", "BK");
INSERT INTO "Templates" VALUES ("103", "1", "BKP");
INSERT INTO "Templates" VALUES ("104", "3", "AR");
INSERT INTO "Templates" VALUES ("105", "1", "RP");
INSERT INTO "Templates" VALUES ("106", "2", "BK");
INSERT INTO "Documents" VALUES ("201", "101", "The Great Adventure");
INSERT INTO "Documents" VALUES ("202", "102", "Mystery of the Old House");
INSERT INTO "Documents" VALUES ("203", "103", "Preview: The Great Adventure");
INSERT INTO "Documents" VALUES ("204", "104", "Science Today");
INSERT INTO "Documents" VALUES ("205", "105", "Annual Financial Report");
INSERT INTO "Documents" VALUES ("206", "106", "Cooking with Style");
INSERT INTO "Documents" VALUES ("207", "106", "Gardening Basics");
INSERT INTO "Documents" VALUES ("208", "102", "Secrets of the Forest");
INSERT INTO "Documents" VALUES ("209", "101", "Journey to the West");
INSERT INTO "Documents" VALUES ("210", "104", "Tech Innovations 2024");