Skip to content

Data Storage

Warning

Currently, all the data stored is in plain. This means no encryption is done on the content sent by the users. While this is fine as long as you deploy the bot only for your personal groups, it can have unwanted implications if it is shared publicly.

Patrizio keeps two kinds of data:

  • Filters and their metadata – stored in a pure‑Go SQLite database (modernc.org/sqlite). The repository lives in internal/adapter/sqlite/repository.go. It uses queries generated by sqlc from the .sql files under internal/database/queries.

  • Media files – stored on the local filesystem via afero. The storage adapter in internal/adapter/storage/storage.go simply reads and writes files. It writes to the directory defined by Config.MediaPath().

SQLite Repository

The repository is instantiated in cmd/patrizio/main.go. sqlite.New(db) returns a *sqlite.Repository that implements the FilterRepository interface. It provides CRUD helpers such as FindMatchingFilters and CreateFilter.

The schema itself is defined by goose migrations in the migrations/ directory. internal/database/database.go opens the database and database.Migrate applies any pending migrations.

Media Repository

The storage adapter uses afero.NewOsFs() to read/write files. When a media filter is added the bot writes the file to the configured media directory and stores its SHA‑512 hash in the database. Later the handler looks up the file path with deps.MediaStorage.Path(filter.MediaHash).