Add class NodaDbAdmin

This commit is contained in:
Joshua Ramon Enslin 2023-08-15 14:42:07 +02:00
parent 831dbca091
commit cb6d0d7b06
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

53
src/NodaDbAdmin.php Normal file
View File

@ -0,0 +1,53 @@
<?PHP
/**
* Class for setting up databases.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
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 . "`");
}
}