Database Configuration

The Motels plugin supports multiple database options to store and manage motel data. You can choose between local storage (SQLite or H2) or an external MySQL database.

Configuration

The database configuration is managed in the config.yml file. Here's a breakdown of the available options:

# LOCAL DATABASE OPTIONS
local-database-options:
  use-sqlite: true

# EXTERNAL DATABASE
mysql:
  enabled: false
  development: false
  dev-database:
    HOST: "localhost"
    PORT: 3306
    DATABASE: "dbname"
    USER: "root"
    PASSWORD: "password"
  production-database:
    HOST: "localhost"
    PORT: 3306
    DATABASE: "dbname"
    USER: "root"
    PASSWORD: "password"

Local Database Options

By default, the plugin uses a local database for data storage. You can choose between SQLite and H2 databases.

  • use-sqlite: Set to true to use SQLite, or false to use H2 database.

When using a local database:

  • SQLite database file will be created as database.sqlite in the plugin's data folder.

  • H2 database files will be created with the prefix localdb in the plugin's data folder.

External MySQL Database

To use an external MySQL database, you need to configure the following settings:

  1. Set mysql.enabled to true.

  2. Choose between development and production database configurations:

    • Set mysql.development to true for development database, false for production.

Development Database Configuration

dev-database:
  HOST: "localhost"
  PORT: 3306
  DATABASE: "dbname"
  USER: "root"
  PASSWORD: "password"

Production Database Configuration

yproduction-database:

  HOST: "localhost"
  PORT: 3306
  DATABASE: "dbname"
  USER: "root"
  PASSWORD: "password"

Replace the values with your actual MySQL server details.

Connection Pool

The plugin uses HikariCP for efficient database connection pooling. Some notable settings:

  • Maximum pool size: 10 connections

  • Auto-reconnect: enabled

  • SSL: disabled

Important Notes

  1. When switching between database types (local to MySQL or vice versa), ensure you have a proper data migration strategy in place to prevent data loss.

  2. For MySQL connections, the plugin uses the JDBC URL format:

    Copyjdbc:mysql://HOST:PORT/DATABASE?allowPublicKeyRetrieval=true&useSSL=false
  3. The plugin will log the database type it's using on startup:

    • "Using MySQL development database."

    • "Using MySQL production database."

    • "Using local database."

  4. If you encounter any database connection issues, check the server console for error messages. The plugin will log any database startup errors.

  5. When the server shuts down or the plugin is disabled, the database connection will be properly closed to prevent resource leaks.

By configuring these options, you can choose the most suitable database setup for your server environment, whether it's a local SQLite/H2 database for simpler setups or a MySQL database for more complex, multi-server configurations.

Last updated