初步实现mysql适配,但暂时存在returning语法缺失问题

This commit is contained in:
zhangyuheng 2024-06-17 17:51:43 +08:00
parent 2299630e15
commit 03cb1af603
3 changed files with 78 additions and 66 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.32.0-beta</version>
<version>1.33.0-beta</version>
<packaging>jar</packaging>
<name>Dominion</name>
@ -82,7 +82,7 @@
<dependency>
<groupId>cn.lunadeer</groupId>
<artifactId>MinecraftPluginUtils</artifactId>
<version>1.3.2-SNAPSHOT</version>
<version>1.3.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.BlueMap-Minecraft</groupId>

View File

@ -8,65 +8,78 @@ public class DatabaseTables {
String sql = "";
// player name
sql = "CREATE TABLE IF NOT EXISTS player_name (" +
" id SERIAL PRIMARY KEY," +
" uuid VARCHAR(36) NOT NULL UNIQUE," +
" last_known_name TEXT NOT NULL," +
" last_join_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" +
");";
Dominion.database.query(sql);
Dominion.database.createTableIfNotExists(
"player_name",
new String[]{"id", "uuid", "last_known_name", "last_join_at"},
new String[]{"SERIAL PRIMARY KEY", "VARCHAR(36) NOT NULL UNIQUE", "TEXT NOT NULL", "TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"},
null
);
// dominion table
sql = "CREATE TABLE IF NOT EXISTS dominion (" +
" id SERIAL PRIMARY KEY," +
" owner VARCHAR(36) NOT NULL," +
" name TEXT NOT NULL UNIQUE," +
" world TEXT NOT NULL," +
" x1 INT NOT NULL," +
" y1 INT NOT NULL," +
" z1 INT NOT NULL," +
" x2 INT NOT NULL," +
" y2 INT NOT NULL," +
" z2 INT NOT NULL," +
" parent_dom_id INT NOT NULL DEFAULT -1," +
" join_message TEXT NOT NULL DEFAULT '欢迎', " +
" leave_message TEXT NOT NULL DEFAULT '再见', " +
" FOREIGN KEY (owner) REFERENCES player_name(uuid) ON DELETE CASCADE," +
" FOREIGN KEY (parent_dom_id) REFERENCES dominion(id) ON DELETE CASCADE" +
");";
Dominion.database.query(sql);
Dominion.database.createTableIfNotExists(
"dominion",
new String[]{"id",
"owner",
"name",
"world",
"x1", "y1", "z1", "x2", "y2", "z2",
"parent_dom_id",
"join_message",
"leave_message"},
new String[]{
"SERIAL PRIMARY KEY",
"VARCHAR(36) NOT NULL",
"TEXT NOT NULL UNIQUE",
"TEXT NOT NULL", "INT NOT NULL", "INT NOT NULL", "INT NOT NULL", "INT NOT NULL", "INT NOT NULL", "INT NOT NULL",
"INT NOT NULL DEFAULT -1",
"TEXT NOT NULL DEFAULT '欢迎'",
"TEXT NOT NULL DEFAULT '再见'"},
new String[]{
"FOREIGN KEY (owner) REFERENCES player_name(uuid) ON DELETE CASCADE",
"FOREIGN KEY (parent_dom_id) REFERENCES dominion(id) ON DELETE CASCADE"
}
);
// player privilege
sql = "CREATE TABLE IF NOT EXISTS player_privilege (" +
" id SERIAL PRIMARY KEY," +
" player_uuid VARCHAR(36) NOT NULL," +
" dom_id INT NOT NULL," +
Dominion.database.createTableIfNotExists(
"player_privilege",
new String[]{"id", "player_uuid", "dom_id", "admin"},
new String[]{"SERIAL PRIMARY KEY", "VARCHAR(36) NOT NULL", "INT NOT NULL", "BOOLEAN NOT NULL DEFAULT FALSE"},
new String[]{
"UNIQUE (player_uuid, dom_id)",
"FOREIGN KEY (player_uuid) REFERENCES player_name(uuid) ON DELETE CASCADE",
"FOREIGN KEY (dom_id) REFERENCES dominion(id) ON DELETE CASCADE"
}
);
" admin BOOLEAN NOT NULL DEFAULT FALSE," +
Dominion.database.insertRowIfNotExists("player_name",
new String[]{"id", "uuid", "last_known_name"},
new String[]{"-1", "00000000-0000-0000-0000-000000000000", "server"},
0
);
" UNIQUE (player_uuid, dom_id)," +
" FOREIGN KEY (player_uuid) REFERENCES player_name(uuid) ON DELETE CASCADE," +
" FOREIGN KEY (dom_id) REFERENCES dominion(id) ON DELETE CASCADE" +
");";
Dominion.database.query(sql);
sql = "INSERT INTO player_name (" +
"id, uuid, last_known_name" +
") VALUES (" +
"-1, '00000000-0000-0000-0000-000000000000', 'server'" +
") ON CONFLICT DO NOTHING;";
Dominion.database.query(sql);
sql = "INSERT INTO dominion (" +
"id, owner, name, world, x1, y1, z1, x2, y2, z2, parent_dom_id, join_message, leave_message" +
") VALUES (" +
"-1, '00000000-0000-0000-0000-000000000000', '根领地', 'all', " +
"-2147483648, -2147483648, -2147483648, " +
"2147483647, 2147483647, 2147483647, -1, " +
"'欢迎', '再见'" +
") ON CONFLICT DO NOTHING;";
Dominion.database.query(sql);
Dominion.database.insertRowIfNotExists("dominion",
new String[]{
"id",
"owner",
"name",
"world",
"x1", "y1", "z1", "x2", "y2", "z2",
"parent_dom_id",
"join_message",
"leave_message"},
new String[]{
"-1",
"00000000-0000-0000-0000-000000000000",
"根领地",
"all",
"-2147483648", "-2147483648", "-2147483648",
"2147483647", "2147483647", "2147483647",
"-1",
"欢迎",
"再见"},
0
);
for (Flag flag : Flag.getAllDominionFlags()) {
Dominion.database.addColumnIfNotExists("dominion",
@ -84,16 +97,15 @@ public class DatabaseTables {
Dominion.database.addColumnIfNotExists("dominion", "tp_location", "TEXT NOT NULL DEFAULT 'default'");
// 1.31.0
sql = "CREATE TABLE IF NOT EXISTS privilege_template (" +
" id SERIAL PRIMARY KEY," +
" creator VARCHAR(36) NOT NULL," +
" name TEXT NOT NULL," +
" admin BOOLEAN NOT NULL DEFAULT FALSE," +
" UNIQUE (creator, name)," +
" FOREIGN KEY (creator) REFERENCES player_name(uuid) ON DELETE CASCADE" +
");";
Dominion.database.query(sql);
Dominion.database.createTableIfNotExists(
"privilege_template",
new String[]{"id", "creator", "name", "admin"},
new String[]{"SERIAL PRIMARY KEY", "VARCHAR(36) NOT NULL", "TEXT NOT NULL", "BOOLEAN NOT NULL DEFAULT FALSE"},
new String[]{
"UNIQUE (creator, name)",
"FOREIGN KEY (creator) REFERENCES player_name(uuid) ON DELETE CASCADE"
}
);
for (Flag flag : Flag.getAllPrivilegeFlags()) {
Dominion.database.addColumnIfNotExists("privilege_template",

View File

@ -1,5 +1,5 @@
Database:
Type: sqlite # pgsql, sqlite
Type: sqlite # pgsql, sqlite, mysql
Host: localhost
Port: 5432
Name: dominion