discord-bot/CompatBot/Database
2020-08-01 16:23:50 +05:00
..
Migrations metacritic table and first pass on the import command 2020-04-03 19:19:49 +05:00
Providers limit in-memory caching duration times 2020-08-01 16:23:50 +05:00
BotDb.cs fix filters 2020-07-03 13:55:34 +05:00
DbImporter.cs refactor to use using statement whenever it makes sense 2019-11-25 18:07:01 +05:00
NamingConventionConverter.cs fix remaining issues with the code after upgrading to 3.0 2019-11-01 00:05:54 +05:00
PrimaryKeyConvention.cs fix remaining issues with the code after upgrading to 3.0 2019-11-01 00:05:54 +05:00
readme.md typo 2019-08-26 20:41:57 +05:00
ThumbnailDb.cs tweak mc import to cover all available games 2020-04-03 21:02:55 +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.