pub async fn create_meta_table(pool: &Pool<MySql>) -> Result<()>
Expand description
Creates the metadata table in the database if it doesn’t already exist.
This function ensures that the system has a place to store key-value metadata. It uses a mutex to prevent multiple threads from attempting to create the table simultaneously, and includes schema optimizations like indices and uniqueness constraints.
§Arguments
pool
- Database connection pool for executing the query
§Returns
Ok(())
- Table was successfully created or already existedErr(anyhow::Error)
- Failed to create the table
§Concurrency
This function acquires the global metadata mutex to ensure thread safety. If the table already exists, it returns immediately without performing any changes.
§Schema
The metadata table is created with the following schema:
id
: Auto-incrementing primary keykey
: Unique string identifier (indexed for fast lookups)value
: Text field storing the metadata valuecreated_at
: Timestamp of when the record was createdupdated_at
: Timestamp of the last update to the record