Skip to content

Data and Environments

willianpm edited this page Mar 14, 2026 · 1 revision

Data and Environments

Environment Selection

Environment is selected by APP_ENV:

  • prod (default)
  • staging

Data directory is resolved as:

  • data/environments/prod
  • data/environments/staging

Managed Data Files

Each environment keeps the same file set:

  • active-polls.json
  • draft-polls.json
  • mensalistas.json
  • role-bindings.json
  • criadores-internos.json
  • historico-votacoes.json

The file handler guarantees initialization and read/write consistency.

Runtime Maps

In memory structures:

  • client.activePolls: map of active poll messageId -> poll object
  • client.draftPolls: map of draft id -> draft object

Persistence model:

  • Runtime changes are persisted to JSON files on updates.
  • Startup reloads JSON into runtime maps.

Startup Data Maintenance

During boot sequence:

  • Missing files are created.
  • Active polls are normalized for compatibility.
  • Drafts older than 90 days are deleted.
  • Reactions are synchronized to recover state after downtime.
  • Vote-limit violations are corrected.

Migration

Legacy data migration script:

npm run migrate:data

Clone this wiki locally