Skip to main content

Writing a plugin? This topic in the developer documentation

Database module

The Database module gives each plugin that uses it a database of its own. Out of the box that is an SQLite file in the plugin's folder, and nothing has to be set up; you move it to H2, MySQL, MariaDB or PostgreSQL by editing one file.

Installing​

Install VersatiaModule-Database-0.0.1.jar next to VersatiaCore when a plugin lists VersatiaModule-Database under depend:. At its first start Paper downloads the module's libraries (HikariCP and the H2, MariaDB and PostgreSQL drivers) into libraries/, which needs access to Maven Central once; the SQLite and MySQL drivers come with Paper.

EngineDataOldest server
sqlitea file in the plugin's folder, database.dbSQLite 3.35
h2a file in the plugin's folder, database.mv.dbH2 2.1
mysqla MySQL server, port 3306; reaches MariaDB tooMySQL 8.0.19
mariadba MariaDB server, port 3306MariaDB 10.3
postgresqla PostgreSQL server, port 5432PostgreSQL 12

The module creates tables, never databases: on a database server, create the database (and on PostgreSQL the schema) before the first start.

The files​

FileWhat it sets
plugins/<Plugin>/database.ymlwhere one plugin's data lives, its pool, timings and table prefix; written by the module at the first open (database.yml)
plugins/VersatiaModule-Database/connections.ymlconnections several plugins share, and the connection of plugins installed later (connections.yml)
plugins/VersatiaModule-Database/config.ymldefaults: for every plugin whose database.yml leaves a key out (config.yml)

Common tasks​

You want toRead
move a plugin from SQLite to MySQL, with its dataChanging the database
put several plugins on one MySQL databaseconnections.yml
keep the password out of the fileSecrets in the file
see what every database is doingStatus
apply an edited fileReloading
find slow statementsLogs
understand a message in the logTroubleshooting

At start every plugin logs one line saying where its data is:

[Shop] SQLITE database.db, prefix shop_, schema V3