minimost.common
minimost.common
Shared path helpers and per-user database initialisation.
This module provides two things:
Path resolution — a single
DB_DIRconstant anduser_db_path()so every other module refers to the same on-disk location without duplicating the path logic.Schema bootstrap —
init_user_db()creates (or opens) a user’s SQLite database and ensures themessagestable exists with the full column set.
Module-level attributes
- DB_DIRpathlib.Path
Absolute path to the
users/directory that stores all per-user SQLite database files. The directory is created lazily byinit_user_db()the first time it is called.
- minimost.common.user_db_path(username: str) Path[source]
Return the absolute filesystem path for a user’s SQLite database.
The path follows the pattern
<project_root>/users/<username>.db. This function does not create the file or its parent directory — useinit_user_db()for that.- Parameters:
username (str) – The account username. Must be a valid filename component (alphanumeric, hyphens, and underscores).
- Returns:
Absolute path to the user’s
.dbfile.- Return type:
Example:
path = user_db_path("alice") # e.g. PosixPath('/srv/minimost/users/alice.db')
- minimost.common.init_user_db(username: str)[source]
Create the per-user SQLite database and ensure the schema is current.
This function is idempotent: calling it multiple times on the same username is safe because the
CREATE TABLE IF NOT EXISTSguard prevents duplicate table creation.What it does:
Creates the
users/directory if it does not already exist.Opens (or creates)
users/<username>.dbwith SQLite.Enables WAL (Write-Ahead Logging) journal mode for better concurrency under simultaneous reads from multiple Gunicorn workers.
Creates the
messagestable if it is absent.
Messages table schema:
Column
Type
Description
idINTEGER PK
Auto-increment primary key.
channelTEXT
Public channel name (e.g.
"general") or DM identifier (e.g."dm:alice:bob").senderTEXT
Username of the message author.
contentTEXT
Message body text.
NULLfor image-only messages.content_typeTEXT
Always
'text'for the current version; reserved for future media types.filenameTEXT
Uploaded image filename stored in
uploads/.NULLfor text-only messages.tsREAL
Unix timestamp (seconds, floating-point) at which the message was sent. Used as the primary ordering key and as the cross-user identity token for edits, deletes, and reactions.
editedINTEGER
Boolean flag (0/1) —
1when the message body has been modified after initial send.edited_tsREAL
Unix timestamp of the most recent edit.
readINTEGER
Per-user read flag (0/1). The sender’s copy is always inserted as
read=1; recipients start at0.deletedINTEGER
Soft-delete flag (0/1). Deleted messages are retained in the database so that tombstones can be propagated to clients that have already cached the message.
deleted_tsREAL
Unix timestamp when the message was deleted.
reply_to_idINTEGER FK
Foreign key to
messages.id— the parent message that this message is replying to, orNULL.reactionsTEXT
Legacy JSON column; reactions are now stored in the shared
presence.db::message_reactionstable. Kept for schema compatibility.reactions_tsREAL
Unix timestamp updated whenever a reaction is toggled. The polling query uses this to detect reaction changes without re-fetching the whole message list.
mentionsTEXT
Reserved for future
@mentiontracking.metadataTEXT
Reserved for future structured metadata.
client_msg_idTEXT
Client-generated deduplication token (not currently enforced server-side).
expires_tsREAL
Unix timestamp after which the associated upload file may be deleted by
minimost.clean.- Parameters:
username (str) – Account username whose database should be initialised.
- Returns:
None
Messages Table Schema
The messages table created by minimost.common.init_user_db()
has the following columns:
Column |
Type |
Description |
|---|---|---|
|
INTEGER PK |
Auto-increment primary key (differs across per-user databases). |
|
TEXT NOT NULL |
Public channel name or DM identifier ( |
|
TEXT NOT NULL |
Username of the message author. |
|
TEXT |
Message text body. |
|
TEXT |
Always |
|
TEXT |
UUID-based image filename. |
|
REAL NOT NULL |
Unix timestamp (seconds, floating-point). Shared across all user copies of the same message. |
|
INTEGER (0/1) |
Whether this message has been edited. |
|
REAL |
Timestamp of the most recent edit. |
|
INTEGER (0/1) |
Per-user read flag. Sender’s copy is inserted as |
|
INTEGER (0/1) |
Soft-delete flag. |
|
REAL |
Timestamp of deletion. |
|
INTEGER FK |
Foreign key to |
|
TEXT |
Legacy column (unused). Reactions are in |
|
REAL |
Updated when a reaction is toggled; triggers polling pickup. |
|
TEXT |
Reserved for future |
|
TEXT |
Reserved for future structured metadata. |
|
TEXT |
Client-generated deduplication token. |
|
REAL |
Expiry timestamp for the associated upload file. |