Implement complete database structure
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Bea 2022-10-23 17:24:32 +02:00
parent 3b07c687c4
commit c40a857f8b
1 changed files with 45 additions and 11 deletions

View File

@ -4,6 +4,8 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class DatabaseManager
{
@ -58,21 +60,53 @@ public class DatabaseManager
public boolean initDb()
{
String sql = "CREATE TABLE IF NOT EXISTS pronouns (" +
"player text NOT NULL," +
"main_pronoun text," +
"secondary_pronoun text" +
");";
List<String> newTables = new ArrayList<>();
try (Statement stmt = dbConnection.createStatement()) {
// create a new table
stmt.execute(sql);
} catch (SQLException e) {
logger.err(e.getMessage());
return false;
newTables.add("CREATE TABLE IF NOT EXISTS players (" +
"player text NOT NULL," +
"main_pronoun_id integer," +
"secondary_pronoun_id integer" +
");");
newTables.add("CREATE TABLE IF NOT EXISTS pronouns (\" +\n" +
" \"pronoun text,\" +\n" +
" \"id integer\" +\n" +
" \");");
for(String sql : newTables)
{
try (Statement stmt = dbConnection.createStatement()) {
// execute the statement
stmt.execute(sql);
} catch (SQLException e) {
logger.err(e.getMessage());
return false;
}
}
return true;
}
/**
* DB STRUCTURE
* TABLE 1: PLAYERS
* -----------------------------------------------------------------
* | name | main_pronoun_id | secondary_pronoun_id |
* -----------------------------------------------------------------
* | AstroBea | 1 | 2 |
* | Notch | 3 | 1 |
* -----------------------------------------------------------------
*
*
* TABLE 2: PRONOUNS
* --------------------------
* | pronoun | id |
* --------------------------
* | she | 1 |
* | her | 2 |
* | he | 3 |
* --------------------------
*
*/
}