1 development.postgres
qwerinope edited this page 2026-02-27 16:54:44 +01:00

Postgres

The bot uses postgres for storing inventories, getloot stats, wallets and all other long-term things that need to be stored.

Here is a graph of the postgres database:

classDiagram
direction BT
class anivTimeouts {
   integer user
   varchar message
   varchar anivBot
   integer duration
   timestamp created
   boolean timeout
   uuid id
}
class auth {
   jsonb accesstoken
   integer id
}
class cheerEvents {
   integer user
   varchar event
   timestamp created
   varchar status
   uuid id
}
class cheers {
   integer user
   integer amount
   timestamp created
   uuid id
}
class events {
   integer user
   timestamp created
   uuid usedItem
   uuid cheer
   uuid getLoot
   boolean refunded
   uuid id
}
class getLoots {
   integer user
   integer qbucks
   jsonb items
   timestamp created
   varchar trigger
   uuid id
}
class timeouts {
   integer user
   integer target
   varchar item
   timestamp created
   uuid cheer
   uuid usedItem
   uuid id
}
class usedItems {
   integer user
   varchar item
   timestamp created
   uuid id
}
class users {
   varchar username
   integer balance
   jsonb inventory
   integer id
}

anivTimeouts  -->  users : user.id
cheerEvents  -->  users : user.id
cheers  -->  users : user.id
events  -->  cheerEvents : cheer.id
events  -->  getLoots : getLoot.id
events  -->  usedItems : usedItem.id
events  -->  users : user.id
getLoots  -->  users : user.id
timeouts  -->  cheerEvents : cheer.id
timeouts  -->  usedItems : usedItem.id
timeouts  -->  users : user.id
timeouts  -->  users : target.id
usedItems  -->  users : user.id

The only table without relations is auth, because this one stores twitch auth data.

All postgres interactions should happen within the db directory.

The events table stores a reference to a record in usedItems, getLoots and/or cheerEvents. Here are some examples to show how this table works:

  • A superloot event has both a cheer event, as well as a getloot record. The events table links them together.
  • A 666 cheer event failed. The events stores that the cheer event got refunded.
  • A user used a TNT, this is stored in the events

The purpose of setting up events like this is so that later on, we can undo specific events. That's why timeouts also has a foreign key of cheerEvents and usedItems.