database¶
database ¶
Database initialization and admin bootstrap for SQLite persistence.
Handles: - Schema creation (4 tables: users, refresh_tokens, sessions, messages) - Admin user bootstrap from environment variables - Legacy session migration from markdown files to SQLite
Always uses parameterized queries (never f-strings) per T-03-01.
init_db
async
¶
Initialize the SQLite database schema idempotently.
Creates 4 tables (users, refresh_tokens, sessions, messages) if they don't already exist. Safe to call multiple times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
str
|
Filesystem path to the SQLite database file. |
required |
ensure_admin
async
¶
Create the admin user from environment variables and hardcoded bootstrap accounts.
Reads ALKIVIADES_ADMIN_EMAIL and ALKIVIADES_ADMIN_PASSWORD from env for a deployment-specific admin (optional). Always creates two hardcoded bootstrap accounts if they don't already exist: - Admin: i.d.lazaridis@gmail.com - Demo: d.e.monstrate@alkiviades.cc
Skips any user whose email already exists in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
str
|
Filesystem path to the SQLite database file. |
required |
migrate_legacy_sessions
async
¶
Migrate legacy markdown sessions to SQLite.
Reads sessions from the sessions/ directory and inserts them into the SQLite database, assigning them to the admin user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
str
|
Filesystem path to the SQLite database file. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of sessions migrated. |