discord-bot/CompatBot/Database
13xforever 8518b7824d update handling of bot usage stats
* wrap everything inside the provider
* do hour-long buckets to workaround the long-standing issue of sticky data bias
* remove stale data on stats restore instead of nuking-n-paving on every stat save
2022-07-04 21:48:32 +05:00
..
Migrations update handling of bot usage stats 2022-07-04 21:48:32 +05:00
Providers update handling of bot usage stats 2022-07-04 21:48:32 +05:00
BotDb.cs update handling of bot usage stats 2022-07-04 21:48:32 +05:00
DbImporter.cs use file-scoped namespaces to reduce nesting 2022-06-30 00:59:46 +05:00
HardwareDb.cs made installid the only key and moved some things around 2022-06-30 00:44:56 +05:00
NamingConventionConverter.cs use file-scoped namespaces to reduce nesting 2022-06-30 00:59:46 +05:00
PrimaryKeyConvention.cs use file-scoped namespaces to reduce nesting 2022-06-30 00:59:46 +05:00
readme.md typo 2019-08-26 20:41:57 +05:00
ThumbnailDb.cs use file-scoped namespaces to reduce nesting 2022-06-30 00:59:46 +05:00

Databases

Currently we use Entity Framework Core as an O/RM and SQLite as a storage. Among easier code generation, ef core allows for automated database schema migrations that are persisted in the Migrations folder.

There are some data provider classes for easier access and management, but most of the time you'll see direct access an manipulation of the data throughout the code base.

After changing the classes you need to generate a new migration using dotnet ef tools

$ dotnet ef migrations add -c <DbClass> <MigrationName>

Note that ef tools come bundled with dotnet sdk 2.x, but require manual installation starting with dotnet sdk 3.0.

BotDb, ThumbnailDb

Two main database description classes used to store settings and PSN metadata respectively.

Note that due to legacy requirements, every table has a numeric primary key with auto increment value, even if it is never used.

BotDb

Contains the following tables that hold bot runtime configuration:

bot-state

A simple key-value table for saving any miscellaneous data that is needed.

moderator

Stores bot roles (mods and sudoers).

piracystring

Stores content moderation filter descriptions, including filter trigger string, trigger context, validating regex, custom message, and required action flags.

warning

Stores user warning history, including user IDs, publicly visible comment on the reason, and privately visible context in case of automated warnings issued by the bot.

explanation

Stores explanation descriptions and data: term as a key, text for an explanation, and optional file attachment as a binary blob.

disabled-commands, whitelisted-invites

Simple lists of the associated data.

event-schedule

Contains information about the events: date and time intervals, titles, etc.

stats

This table is used for persisting stat caches in case of process restart.

ThumbnailDb

Contains mostly PSN-related metadata in the following tables:

state

A key-value storage of the PSN crawling state, and some other named time stamps.

thumbnail

Contains mapping for the product code, content ID, source thumbnail URL, and re-uploaded cached thumbnail URL.

title-info

??? Seems to duplicate thumbnail table, with added optional column for the embed color. TBH I don't remember how this happened. I need to remove this later.

syscall-info

Contains information about what game used what function from what firmware or kernel module.

syscall-to-product-map

This is a utility table that contains foreign keys that tie thumbnail and syscall-info tables together to allow required JOINs for queries.

DbImporter

This class is handling all the import logic from the legacy python version of the bot, and also applying all the available migrations on program start up.