diff --git a/src/NodaDbAdmin.php b/src/NodaDbAdmin.php new file mode 100644 index 0000000..619dd86 --- /dev/null +++ b/src/NodaDbAdmin.php @@ -0,0 +1,53 @@ + + */ +declare(strict_types = 1); + +/** + * Class for setting up databases. + */ +final class NodaDbAdmin { + /** + * Sets up a search index for vocabulary searches. + * + * @param MDMysqli $mysqli_manticore Manticore DB connection. + * @param string $index_name Name of the search index. + * + * @return void + */ + public static function resetVocabularySearchIndex(MDMysqli $mysqli_manticore, string $index_name):void { + + $mysqli_manticore->query("DROP TABLE IF EXISTS `" . $index_name . "`"); + $mysqli_manticore->query("CREATE TABLE IF NOT EXISTS `" . $index_name . "` + (`entry_id` int, + `language` string, + `name` text, + `description` text, + `timestamp` timestamp) min_infix_len = '3'"); + MDConsole::write("Create table `" . $index_name . "`"); + + } + + /** + * Ensures that a search index is set up. + * + * @param MDMysqli $mysqli_manticore Manticore DB connection. + * @param string $index_name Name of the search index. + * + * @return void + */ + public static function setupVocabularySearchIndex(MDMysqli $mysqli_manticore, string $index_name):void { + + $mysqli_manticore->query("CREATE TABLE IF NOT EXISTS `" . $index_name . "` + (`entry_id` int, + `language` string, + `name` text, + `description` text, + `timestamp` timestamp) min_infix_len = '3'"); + MDConsole::write("Create table `" . $index_name . "`"); + + } +}