Skip to main content
MQTT Gateway uses MariaDB or MySQL to store configuration, message data, and routing rules. The database is automatically initialized on first run.

Database requirements

MQTT Gateway requires:
  • MariaDB or MySQL database server
  • Database created and accessible
  • User credentials with full access to the database

Connection configuration

Configure the database connection using environment variables in your .env file:
See environment variables for detailed parameter descriptions.

Database schema

The gateway uses SQLAlchemy ORM to manage the database schema. On startup, it automatically creates the required tables if they don’t exist.

Tables created

mqtt_servers

Stores MQTT broker connection information.

flows

Defines message routing rules from MQTT topics to destinations.

data

Stores received MQTT message data when using database action.

Automatic initialization

The database schema is automatically created when you start the gateway for the first time:
This creates all tables defined in the SQLAlchemy models.

Default MQTT server seeding

On first run, if no enabled MQTT server exists in the database, a default server is automatically created:
Update the default MQTT server configuration in your database after first run to match your actual MQTT broker settings.

Connection pooling

The gateway uses SQLAlchemy’s connection pooling with the pool_pre_ping option enabled:
This ensures that stale database connections are automatically refreshed, improving reliability for long-running processes.

Session management

Database sessions are created using a session factory with these settings:
The expire_on_commit=False setting prevents objects from being expired after commit, which is useful when passing objects between different parts of the application.