Database Mechanism 
Monibuca provides database support functionality, allowing database configuration and usage in both global settings and plugins.
Configuration 
Global Configuration 
Database can be configured in global settings using these fields:
global:
  db:
    dsn: "database connection string"
    dbtype: "database type"Plugin Configuration 
Each plugin can have its own database configuration:
pluginName:
  db:
    dsn: "database connection string"
    dbtype: "database type"Database Initialization Process 
Global Database Initialization 
When the server starts, if
dsnis configured, it attempts to connect to the databaseAfter successful connection, the following models are automatically migrated:
- User table
 - PullProxy table
 - PushProxy table
 - StreamAliasDB table
 
If login is enabled (
Admin.EnableLogin = true), users are created or updated based on the configuration fileIf no users exist in the database, a default admin account is created:
- Username: admin
 - Password: admin
 - Role: admin
 
Plugin Database Initialization 
- During plugin initialization, the plugin's 
dsnconfiguration is checked - If the plugin's 
dsnmatches the global configuration, the global database connection is used - If the plugin configures a different 
dsn, a new database connection is created - If the plugin implements the Recorder interface, the RecordStream table is automatically migrated
 
Database Usage 
Global Database Access 
The global database can be accessed through the Server instance:
server.DBPlugin Database Access 
Plugins can access their database through their instance:
plugin.DBImportant Notes 
- Database connection failures will disable related functionality
 - Plugins using independent databases need to manage their own database connections
 - Database migration failures will cause plugins to be disabled
 - It's recommended to reuse the global database connection when possible to avoid creating too many connections
 
Built-in Tables 
User Table 
Stores user information, including:
- Username: User's name
 - Password: User's password
 - Role: User's role (admin/user)
 
PullProxy Table 
Stores pull proxy configurations
PushProxy Table 
Stores push proxy configurations
StreamAliasDB Table 
Stores stream alias configurations
RecordStream Table 
Stores recording-related information (only created when plugin implements Recorder interface)