From 89b8fd5a01d109979d7820cf1a5d4a62da96c2f8 Mon Sep 17 00:00:00 2001 From: "dorian.hodin" Date: Tue, 31 Jan 2023 19:03:05 +0100 Subject: [PATCH 1/2] Add script for database --- .idea/dataSources.xml | 12 ++ Source/API/script/APIController.php | 3 + Source/API/script/Config/databaseScript.php | 122 ++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 .idea/dataSources.xml create mode 100644 Source/API/script/Config/databaseScript.php diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..1802a0d --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mariadb + true + org.mariadb.jdbc.Driver + jdbc:mariadb://localhost:3306 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/Source/API/script/APIController.php b/Source/API/script/APIController.php index 5e85c66..89fd8aa 100644 --- a/Source/API/script/APIController.php +++ b/Source/API/script/APIController.php @@ -2,8 +2,11 @@ class APIController { + private ScriptDatabase $script; function __construct() { + $this->script = new ScriptDatabase(); + $this->script->executeScript(); try { if (empty($_REQUEST['action'])) { $action = NULL; diff --git a/Source/API/script/Config/databaseScript.php b/Source/API/script/Config/databaseScript.php new file mode 100644 index 0000000..29d1083 --- /dev/null +++ b/Source/API/script/Config/databaseScript.php @@ -0,0 +1,122 @@ +con = connect(); + } + + public function executeScript(): void + { + $queryScript = 'CREATE TABLE `Categorize` ( + `response` int(11) NOT NULL, + `keyword` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `Form` ( + `id` int(11) NOT NULL, + `title` varchar(50) NOT NULL, + `description` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `Keyword` ( + `id` int(11) NOT NULL, + `word` varchar(50) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `ListResponsesOfCandidate` ( + `id` int(11) NOT NULL, + `date` datetime NOT NULL, + `titleForm` varchar(50) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `PossibleResponse` ( + `id` int(11) NOT NULL, + `content` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `Propose` ( + `question` int(11) NOT NULL, + `possibleResponse` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `Question` ( + `id` int(11) NOT NULL, + `content` text NOT NULL, + `type` varchar(50) NOT NULL, + `form` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `Reference` ( + `possibleResponse` int(11) NOT NULL, + `keyword` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `Response` ( + `id` int(11) NOT NULL, + `content` varchar(200) NOT NULL, + `questionContent` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +CREATE TABLE `Submit` ( + `responsesCandidate` int(11) NOT NULL, + `response` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +ALTER TABLE `Categorize` + ADD PRIMARY KEY (`response`,`keyword`), + ADD KEY `keyword` (`keyword`); +ALTER TABLE `Form` + ADD PRIMARY KEY (`id`); +ALTER TABLE `Keyword` + ADD PRIMARY KEY (`id`); +ALTER TABLE `ListResponsesOfCandidate` + ADD PRIMARY KEY (`id`); +ALTER TABLE `PossibleResponse` + ADD PRIMARY KEY (`id`); +ALTER TABLE `Propose` + ADD PRIMARY KEY (`question`,`possibleResponse`), + ADD KEY `possibleResponse` (`possibleResponse`); +ALTER TABLE `Question` + ADD PRIMARY KEY (`id`), + ADD KEY `form` (`form`); +ALTER TABLE `Reference` + ADD PRIMARY KEY (`possibleResponse`,`keyword`), + ADD KEY `keyword` (`keyword`); +ALTER TABLE `Response` + ADD PRIMARY KEY (`id`); +ALTER TABLE `Submit` + ADD PRIMARY KEY (`responsesCandidate`,`response`), + ADD KEY `response` (`response`); +ALTER TABLE `Form` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `Keyword` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `ListResponsesOfCandidate` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `PossibleResponse` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `Question` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `Response` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `Categorize` + ADD CONSTRAINT `Categorize_ibfk_1` FOREIGN KEY (`keyword`) REFERENCES `Keyword` (`id`), + ADD CONSTRAINT `Categorize_ibfk_2` FOREIGN KEY (`response`) REFERENCES `Response` (`id`); +ALTER TABLE `Propose` + ADD CONSTRAINT `Propose_ibfk_1` FOREIGN KEY (`possibleResponse`) REFERENCES `PossibleResponse` (`id`), + ADD CONSTRAINT `Propose_ibfk_2` FOREIGN KEY (`question`) REFERENCES `Question` (`id`); +ALTER TABLE `Question` + ADD CONSTRAINT `Question_ibfk_1` FOREIGN KEY (`form`) REFERENCES `Form` (`id`); +ALTER TABLE `Reference` + ADD CONSTRAINT `Reference_ibfk_1` FOREIGN KEY (`keyword`) REFERENCES `Keyword` (`id`), + ADD CONSTRAINT `Reference_ibfk_2` FOREIGN KEY (`possibleResponse`) REFERENCES `PossibleResponse` (`id`); +ALTER TABLE `Submit` + ADD CONSTRAINT `Submit_ibfk_1` FOREIGN KEY (`response`) REFERENCES `Response` (`id`), + ADD CONSTRAINT `Submit_ibfk_2` FOREIGN KEY (`responsesCandidate`) REFERENCES `ListResponsesOfCandidate` (`id`); +COMMIT;'; + + + $this->con->executeQuery($queryScript); + try { + $test = "SELECT * FROM Categorize;"; + $this->con->executeQuery($test); + }catch (Exception $e){ + echo $e->getMessage(); + } + + + } + +} From cad5db43eafd065770958bab41ea86e91a239210 Mon Sep 17 00:00:00 2001 From: "dorian.hodin" Date: Tue, 31 Jan 2023 19:05:09 +0100 Subject: [PATCH 2/2] Comment the lines --- Source/API/script/APIController.php | 6 +++--- Source/API/script/Config/databaseScript.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/API/script/APIController.php b/Source/API/script/APIController.php index 89fd8aa..6f6e162 100644 --- a/Source/API/script/APIController.php +++ b/Source/API/script/APIController.php @@ -2,11 +2,11 @@ class APIController { - private ScriptDatabase $script; + // private ScriptDatabase $script; function __construct() { - $this->script = new ScriptDatabase(); - $this->script->executeScript(); + // $this->script = new ScriptDatabase(); + // $this->script->executeScript(); try { if (empty($_REQUEST['action'])) { $action = NULL; diff --git a/Source/API/script/Config/databaseScript.php b/Source/API/script/Config/databaseScript.php index 29d1083..07c2306 100644 --- a/Source/API/script/Config/databaseScript.php +++ b/Source/API/script/Config/databaseScript.php @@ -3,7 +3,7 @@ class ScriptDatabase { private Connection $con; - function __construct() { + public function __construct() { $this->con = connect(); }