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,
"Document_ID" INT,
PRIMARY KEY ("Paragraph_ID"),
FOREIGN KEY ("Document_ID") REFERENCES "Documents"("Document_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,
"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 ("GEN", "General Document Template");
INSERT INTO "Ref_Template_Types" VALUES ("REP", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("INV", "Invoice Template");
INSERT INTO "Ref_Template_Types" VALUES ("PRO", "Proposal Template");
INSERT INTO "Ref_Template_Types" VALUES ("MEM", "Memo Template");
INSERT INTO "Templates" VALUES ("101", "GEN", "Standard General Document");
INSERT INTO "Templates" VALUES ("102", "REP", "Monthly Sales Report");
INSERT INTO "Templates" VALUES ("103", "INV", "Customer Invoice");
INSERT INTO "Templates" VALUES ("104", "PRO", "Project Proposal");
INSERT INTO "Templates" VALUES ("105", "GEN", "Internal Memo Template");
INSERT INTO "Templates" VALUES ("106", "REP", "Annual Financial Report");
INSERT INTO "Templates" VALUES ("107", "GEN", "Data Base Document Template");
INSERT INTO "Documents" VALUES ("1", "101", "Meeting Minutes");
INSERT INTO "Documents" VALUES ("2", "102", "Q1 Sales Report");
INSERT INTO "Documents" VALUES ("3", "103", "Invoice #2023-001");
INSERT INTO "Documents" VALUES ("4", "104", "New System Proposal");
INSERT INTO "Documents" VALUES ("5", "105", "Team Update Memo");
INSERT INTO "Documents" VALUES ("6", "107", "Data base");
INSERT INTO "Documents" VALUES ("7", "101", "Project Plan");
INSERT INTO "Documents" VALUES ("8", "106", "2022 Financial Report");
INSERT INTO "Documents" VALUES ("9", "107", "Data base Migration Plan");
INSERT INTO "Paragraphs" VALUES ("1001", "1");
INSERT INTO "Paragraphs" VALUES ("1002", "1");
INSERT INTO "Paragraphs" VALUES ("1003", "2");
INSERT INTO "Paragraphs" VALUES ("1004", "3");
INSERT INTO "Paragraphs" VALUES ("1005", "4");
INSERT INTO "Paragraphs" VALUES ("1006", "5");
INSERT INTO "Paragraphs" VALUES ("1007", "6");
INSERT INTO "Paragraphs" VALUES ("1008", "6");
INSERT INTO "Paragraphs" VALUES ("1009", "7");
INSERT INTO "Paragraphs" VALUES ("1010", "8");
INSERT INTO "Paragraphs" VALUES ("1011", "9");