mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
feat: add support for PostgreSQL data storage (#616)
Signed-off-by: PseudoResonance <[email protected]>
This commit is contained in:
11 files changed
+1386
-17
No files matched your search
@@ -22,6 +22,7 @@ ext {
|
|||||||
set 'sqlite_driver_version', sqlite_driver_version.toString()
|
set 'sqlite_driver_version', sqlite_driver_version.toString()
|
||||||
set 'mysql_driver_version', mysql_driver_version.toString()
|
set 'mysql_driver_version', mysql_driver_version.toString()
|
||||||
set 'mariadb_driver_version', mariadb_driver_version.toString()
|
set 'mariadb_driver_version', mariadb_driver_version.toString()
|
||||||
|
set 'postgresql_driver_version', postgresql_driver_version.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|||||||
@@ -35,10 +35,7 @@ import net.william278.huskhomes.config.Locales;
|
|||||||
import net.william278.huskhomes.config.Server;
|
import net.william278.huskhomes.config.Server;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.config.Spawn;
|
import net.william278.huskhomes.config.Spawn;
|
||||||
import net.william278.huskhomes.database.Database;
|
import net.william278.huskhomes.database.*;
|
||||||
import net.william278.huskhomes.database.H2Database;
|
|
||||||
import net.william278.huskhomes.database.MySqlDatabase;
|
|
||||||
import net.william278.huskhomes.database.SqLiteDatabase;
|
|
||||||
import net.william278.huskhomes.event.BukkitEventDispatcher;
|
import net.william278.huskhomes.event.BukkitEventDispatcher;
|
||||||
import net.william278.huskhomes.hook.Hook;
|
import net.william278.huskhomes.hook.Hook;
|
||||||
import net.william278.huskhomes.hook.PlaceholderAPIHook;
|
import net.william278.huskhomes.hook.PlaceholderAPIHook;
|
||||||
@@ -138,6 +135,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
||||||
case SQLITE -> new SqLiteDatabase(this);
|
case SQLITE -> new SqLiteDatabase(this);
|
||||||
case H2 -> new H2Database(this);
|
case H2 -> new H2Database(this);
|
||||||
|
case POSTGRESQL -> new PostgreSqlDatabase(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
database.initialize();
|
database.initialize();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ dependencies {
|
|||||||
compileOnly "com.mysql:mysql-connector-j:${mysql_driver_version}"
|
compileOnly "com.mysql:mysql-connector-j:${mysql_driver_version}"
|
||||||
compileOnly "org.mariadb.jdbc:mariadb-java-client:${mariadb_driver_version}"
|
compileOnly "org.mariadb.jdbc:mariadb-java-client:${mariadb_driver_version}"
|
||||||
compileOnly "com.h2database:h2:${h2_driver_version}"
|
compileOnly "com.h2database:h2:${h2_driver_version}"
|
||||||
|
compileOnly "org.postgresql:postgresql:${postgresql_driver_version}"
|
||||||
|
|
||||||
compileOnly 'org.jetbrains:annotations:24.1.0'
|
compileOnly 'org.jetbrains:annotations:24.1.0'
|
||||||
compileOnly 'com.google.guava:guava:33.1.0-jre'
|
compileOnly 'com.google.guava:guava:33.1.0-jre'
|
||||||
|
|||||||
@@ -69,10 +69,10 @@ public final class Settings {
|
|||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public static class DatabaseSettings {
|
public static class DatabaseSettings {
|
||||||
|
|
||||||
@Comment("Type of database to use (SQLITE, H2, MYSQL, or MARIADB)")
|
@Comment("Type of database to use (SQLITE, H2, MYSQL, MARIADB, or POSTGRESQL)")
|
||||||
private Database.Type type = Database.Type.SQLITE;
|
private Database.Type type = Database.Type.SQLITE;
|
||||||
|
|
||||||
@Comment("Specify credentials here if you are using MYSQL or MARIADB")
|
@Comment("Specify credentials here if you are using MYSQL, MARIADB, or POSTGRESQL")
|
||||||
private DatabaseCredentials credentials = new DatabaseCredentials();
|
private DatabaseCredentials credentials = new DatabaseCredentials();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -89,7 +89,7 @@ public final class Settings {
|
|||||||
"useUnicode=true", "characterEncoding=UTF-8");
|
"useUnicode=true", "characterEncoding=UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Comment({"MYSQL / MARIADB database Hikari connection pool properties",
|
@Comment({"MYSQL / MARIADB / POSTGRESQL database Hikari connection pool properties",
|
||||||
"Don't modify this unless you know what you're doing!"})
|
"Don't modify this unless you know what you're doing!"})
|
||||||
private PoolOptions poolOptions = new PoolOptions();
|
private PoolOptions poolOptions = new PoolOptions();
|
||||||
|
|
||||||
|
|||||||
@@ -493,7 +493,8 @@ public abstract class Database {
|
|||||||
MYSQL("MySQL", "mysql"),
|
MYSQL("MySQL", "mysql"),
|
||||||
MARIADB("MariaDB", "mariadb"),
|
MARIADB("MariaDB", "mariadb"),
|
||||||
SQLITE("SQLite", "sqlite"),
|
SQLITE("SQLite", "sqlite"),
|
||||||
H2("H2", "h2");
|
H2("H2", "h2"),
|
||||||
|
POSTGRESQL("PostgreSQL", "postgresql");
|
||||||
|
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
private final String protocol;
|
private final String protocol;
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,94 @@
|
|||||||
|
/* Create the positions table if it does not exist */
|
||||||
|
CREATE TABLE IF NOT EXISTS "%positions_table%"
|
||||||
|
(
|
||||||
|
"id" SERIAL,
|
||||||
|
"x" double precision NOT NULL,
|
||||||
|
"y" double precision NOT NULL,
|
||||||
|
"z" double precision NOT NULL,
|
||||||
|
"yaw" real NOT NULL,
|
||||||
|
"pitch" real NOT NULL,
|
||||||
|
"world_name" varchar(255) NOT NULL,
|
||||||
|
"world_uuid" char(36) NOT NULL,
|
||||||
|
"server_name" varchar(255) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Create the players table if it does not exist */
|
||||||
|
CREATE TABLE IF NOT EXISTS "%players_table%"
|
||||||
|
(
|
||||||
|
"uuid" char(36) NOT NULL UNIQUE,
|
||||||
|
"username" varchar(16) NOT NULL,
|
||||||
|
"last_position" integer DEFAULT NULL,
|
||||||
|
"offline_position" integer DEFAULT NULL,
|
||||||
|
"respawn_position" integer DEFAULT NULL,
|
||||||
|
"home_slots" integer NOT NULL DEFAULT 0,
|
||||||
|
"ignoring_requests" boolean NOT NULL DEFAULT FALSE,
|
||||||
|
|
||||||
|
PRIMARY KEY ("uuid"),
|
||||||
|
FOREIGN KEY ("last_position") REFERENCES "%positions_table%" ("id") ON DELETE SET NULL ON UPDATE NO ACTION,
|
||||||
|
FOREIGN KEY ("offline_position") REFERENCES "%positions_table%" ("id") ON DELETE SET NULL ON UPDATE NO ACTION,
|
||||||
|
FOREIGN KEY ("respawn_position") REFERENCES "%positions_table%" ("id") ON DELETE SET NULL ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Create the cooldowns table if it does not exist */
|
||||||
|
CREATE TABLE IF NOT EXISTS "%cooldowns_table%"
|
||||||
|
(
|
||||||
|
"id" SERIAL,
|
||||||
|
"player_uuid" char(36) NOT NULL,
|
||||||
|
"type" varchar(255) NOT NULL,
|
||||||
|
"start_timestamp" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"end_timestamp" timestamp NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
FOREIGN KEY ("player_uuid") REFERENCES "%players_table%" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Create the current cross-server teleports table if it does not exist */
|
||||||
|
CREATE TABLE IF NOT EXISTS "%teleports_table%"
|
||||||
|
(
|
||||||
|
"player_uuid" char(36) NOT NULL UNIQUE,
|
||||||
|
"destination_id" integer NOT NULL,
|
||||||
|
"type" integer NOT NULL DEFAULT 0,
|
||||||
|
|
||||||
|
PRIMARY KEY ("player_uuid"),
|
||||||
|
FOREIGN KEY ("player_uuid") REFERENCES "%players_table%" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
FOREIGN KEY ("destination_id") REFERENCES "%positions_table%" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Create the saved positions table if it does not exist */
|
||||||
|
CREATE TABLE IF NOT EXISTS "%saved_positions_table%"
|
||||||
|
(
|
||||||
|
"id" SERIAL,
|
||||||
|
"position_id" integer NOT NULL,
|
||||||
|
"name" varchar(64) NOT NULL,
|
||||||
|
"description" varchar(255) NOT NULL,
|
||||||
|
"tags" text DEFAULT NULL,
|
||||||
|
"timestamp" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
FOREIGN KEY ("position_id") REFERENCES "%positions_table%" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Create the homes table if it does not exist */
|
||||||
|
CREATE TABLE IF NOT EXISTS "%homes_table%"
|
||||||
|
(
|
||||||
|
"uuid" char(36) NOT NULL UNIQUE,
|
||||||
|
"saved_position_id" integer NOT NULL,
|
||||||
|
"owner_uuid" char(36) NOT NULL,
|
||||||
|
"public" boolean NOT NULL DEFAULT FALSE,
|
||||||
|
|
||||||
|
PRIMARY KEY ("uuid"),
|
||||||
|
FOREIGN KEY ("owner_uuid") REFERENCES "%players_table%" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
FOREIGN KEY ("saved_position_id") REFERENCES "%saved_positions_table%" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Create the warps table if it does not exist */
|
||||||
|
CREATE TABLE IF NOT EXISTS "%warps_table%"
|
||||||
|
(
|
||||||
|
"uuid" char(36) NOT NULL UNIQUE,
|
||||||
|
"saved_position_id" integer NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY ("uuid"),
|
||||||
|
FOREIGN KEY ("saved_position_id") REFERENCES "%saved_positions_table%" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
@@ -46,10 +46,7 @@ import net.william278.huskhomes.config.Locales;
|
|||||||
import net.william278.huskhomes.config.Server;
|
import net.william278.huskhomes.config.Server;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.config.Spawn;
|
import net.william278.huskhomes.config.Spawn;
|
||||||
import net.william278.huskhomes.database.Database;
|
import net.william278.huskhomes.database.*;
|
||||||
import net.william278.huskhomes.database.H2Database;
|
|
||||||
import net.william278.huskhomes.database.MySqlDatabase;
|
|
||||||
import net.william278.huskhomes.database.SqLiteDatabase;
|
|
||||||
import net.william278.huskhomes.event.FabricEventDispatcher;
|
import net.william278.huskhomes.event.FabricEventDispatcher;
|
||||||
import net.william278.huskhomes.hook.FabricImpactorEconomyHook;
|
import net.william278.huskhomes.hook.FabricImpactorEconomyHook;
|
||||||
import net.william278.huskhomes.hook.FabricPlaceholderAPIHook;
|
import net.william278.huskhomes.hook.FabricPlaceholderAPIHook;
|
||||||
@@ -147,6 +144,7 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes
|
|||||||
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
||||||
case SQLITE -> new SqLiteDatabase(this);
|
case SQLITE -> new SqLiteDatabase(this);
|
||||||
case H2 -> new H2Database(this);
|
case H2 -> new H2Database(this);
|
||||||
|
case POSTGRESQL -> new PostgreSqlDatabase(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
database.initialize();
|
database.initialize();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ mysql_driver_version=8.3.0
|
|||||||
mariadb_driver_version=3.3.3
|
mariadb_driver_version=3.3.3
|
||||||
sqlite_driver_version=3.45.2.0
|
sqlite_driver_version=3.45.2.0
|
||||||
h2_driver_version=2.2.220
|
h2_driver_version=2.2.220
|
||||||
|
postgresql_driver_version=42.7.3
|
||||||
commons_pool_version=2.12.0
|
commons_pool_version=2.12.0
|
||||||
|
|
||||||
# Fabric settings
|
# Fabric settings
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ libraries:
|
|||||||
- 'com.mysql:mysql-connector-j:${mysql_driver_version}'
|
- 'com.mysql:mysql-connector-j:${mysql_driver_version}'
|
||||||
- 'org.mariadb.jdbc:mariadb-java-client:${mariadb_driver_version}'
|
- 'org.mariadb.jdbc:mariadb-java-client:${mariadb_driver_version}'
|
||||||
- 'org.xerial:sqlite-jdbc:${sqlite_driver_version}'
|
- 'org.xerial:sqlite-jdbc:${sqlite_driver_version}'
|
||||||
- 'com.h2database:h2:${h2_driver_version}'
|
- 'com.h2database:h2:${h2_driver_version}'
|
||||||
|
- 'org.postgresql:postgresql:${postgresql_driver_version}'
|
||||||
@@ -33,10 +33,7 @@ import net.william278.huskhomes.config.Locales;
|
|||||||
import net.william278.huskhomes.config.Server;
|
import net.william278.huskhomes.config.Server;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.config.Spawn;
|
import net.william278.huskhomes.config.Spawn;
|
||||||
import net.william278.huskhomes.database.Database;
|
import net.william278.huskhomes.database.*;
|
||||||
import net.william278.huskhomes.database.H2Database;
|
|
||||||
import net.william278.huskhomes.database.MySqlDatabase;
|
|
||||||
import net.william278.huskhomes.database.SqLiteDatabase;
|
|
||||||
import net.william278.huskhomes.event.SpongeEventDispatcher;
|
import net.william278.huskhomes.event.SpongeEventDispatcher;
|
||||||
import net.william278.huskhomes.hook.Hook;
|
import net.william278.huskhomes.hook.Hook;
|
||||||
import net.william278.huskhomes.hook.SpongeEconomyHook;
|
import net.william278.huskhomes.hook.SpongeEconomyHook;
|
||||||
@@ -141,6 +138,7 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
|||||||
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
||||||
case SQLITE -> new SqLiteDatabase(this);
|
case SQLITE -> new SqLiteDatabase(this);
|
||||||
case H2 -> new H2Database(this);
|
case H2 -> new H2Database(this);
|
||||||
|
case POSTGRESQL -> new PostgreSqlDatabase(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
database.initialize();
|
database.initialize();
|
||||||
|
|||||||
Reference in new issue
Block a user