Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Database

PolarBot keeps everything in one SQLite file (see Files), opened in WAL mode with foreign keys on and a 5 s busy timeout. Migrations run automatically at startup. Nothing about a flagged message is stored: the mod card in Discord is the only record. Every row of a server is deleted when the bot leaves that server.

Tables and personal data

TableWhat it holdsPersonal dataKept for
guild_settingsPer-server settings: log channel, log level, staff announcements channel.None (server and channel IDs).Until the bot leaves the server (then deleted at once).
role_levelsThe /perms mapping: role → permission level.None (role IDs).Until the bot leaves the server (then deleted at once).
mod_actionsPunishment history: bans, unbans, kicks, timeouts, untimeouts and warns, from commands and from the scanner.Yes: target and moderator user IDs, the reason text, the time.180 days (purged hourly), or until the bot leaves the server.
warnings/warn warnings.Yes: user and moderator IDs, the reason text, the time.180 days (purged hourly), or until the bot leaves the server.
scan_settingsScanner settings: on/off, thresholds, actions, mod role, channel mode, NSFW-link action.None.Until the bot leaves the server (then deleted at once).
scan_channelsScanner channel rules (monitor or exempt).None.Until the bot leaves the server (then deleted at once).
scan_exempt_rolesRoles the scanner skips.None.Until the bot leaves the server (then deleted at once).
scan_domainsThe server’s allow and block lists of domains.None.Until the bot leaves the server (then deleted at once).
training_examplesAnonymized texts of decided scanner cards (Scam / Not scam) for a future classifier.No: mentions, IDs, names, invite codes and URL paths are replaced before storing; no server or user column; the day only.Until exported with polarbot export-training (the export deletes them).
guild_oauthThe /perms authorize grant for command visibility: the refresh token, encrypted (AES-256-GCM, server ID as associated data).The user ID of the admin who authorized, and the encrypted token.Until replaced by a new authorization, found revoked, or the bot leaves the server.
bot_metaProcess-wide state, e.g. announced_version (the last version whose update notice was posted).None.Kept.
scan_stats/scanner status counters: messages flagged and acted on, per server per UTC day.None (two numbers per server and day).30 days (purged hourly), or until the bot leaves the server.
_sqlx_migrationsWhich migrations have run (managed by sqlx). A binary refuses to start on a database migrated by a newer one.None.Kept.

Columns

guild_settings

ColumnTypeNullDefaultKey
guild_idINTEGERyes–primary
localeTEXTno'en'
log_channel_idINTEGERyes–
created_atINTEGERno–
log_levelINTEGERno2
announcements_channel_idINTEGERyes–

role_levels

ColumnTypeNullDefaultKey
guild_idINTEGERno–primary
role_idINTEGERno–primary
levelINTEGERno–

mod_actions

ColumnTypeNullDefaultKey
idINTEGERyes–primary
guild_idINTEGERno–
moderator_idINTEGERno–
target_idINTEGERno–
actionTEXTno–
reasonTEXTyes–
duration_secsINTEGERyes–
created_atINTEGERno–

warnings

ColumnTypeNullDefaultKey
idINTEGERyes–primary
guild_idINTEGERno–
user_idINTEGERno–
moderator_idINTEGERno–
reasonTEXTno–
created_atINTEGERno–

scan_settings

ColumnTypeNullDefaultKey
guild_idINTEGERyes–primary
enabledINTEGERno1
log_thresholdINTEGERno60
delete_thresholdINTEGERno90
punish_thresholdINTEGERno97
punish_actionTEXTno'timeout'
timeout_secsINTEGERno3600
hacked_actionTEXTno'delete_timeout'
mod_role_idINTEGERyes–
allow_invitesINTEGERno0
channel_modeTEXTno'all'
actions_enabledINTEGERno1
updated_atINTEGERno–
nsfw_actionTEXTno'delete'

scan_channels

ColumnTypeNullDefaultKey
guild_idINTEGERno–primary
channel_idINTEGERno–primary
ruleTEXTno–

scan_exempt_roles

ColumnTypeNullDefaultKey
guild_idINTEGERno–primary
role_idINTEGERno–primary

scan_domains

ColumnTypeNullDefaultKey
guild_idINTEGERno–primary
domainTEXTno–primary
listTEXTno–

training_examples

ColumnTypeNullDefaultKey
idINTEGERyes–primary
textTEXTno–
categoryTEXTno–
verdictTEXTno–
created_atINTEGERno–

guild_oauth

ColumnTypeNullDefaultKey
guild_idINTEGERyes–primary
encrypted_refresh_tokenBLOBno–
nonceBLOBno–
authorized_byINTEGERno–
scopeTEXTno–
updated_atINTEGERno–

bot_meta

ColumnTypeNullDefaultKey
keyTEXTyes–primary
valueTEXTno–

scan_stats

ColumnTypeNullDefaultKey
guild_idINTEGERno–primary
dayINTEGERno–primary
flaggedINTEGERno0
actedINTEGERno0

_sqlx_migrations

ColumnTypeNullDefaultKey
versionBIGINTyes–primary
descriptionTEXTno–
installed_onTIMESTAMPnoCURRENT_TIMESTAMP
successBOOLEANno–
checksumBLOBno–
execution_timeBIGINTno–

Migrations

Applied in order, once each, at startup (crates/polarbot/migrations).

FileChanges
0001_core.sqlcreates table guild_settings, creates table role_levels, creates table mod_actions, creates index mod_actions_guild_target, creates table warnings, creates index warnings_guild_user
0002_scanner.sqlcreates table scan_settings, creates table scan_channels, creates table scan_exempt_roles, creates table scan_domains, creates table training_examples, creates index mod_actions_created_at, creates index warnings_created_at, fills scan_settings
0003_logging.sqladds column guild_settings.log_level
0004_oauth.sqlcreates table guild_oauth
0005_bot_meta.sqlcreates table bot_meta
0006_scan_stats.sqlcreates table scan_stats
0007_nsfw_links.sqladds column scan_settings.nsfw_action, updates scan_settings
0008_announcements_channel.sqladds column guild_settings.announcements_channel_id