Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SQLite for data storage #63

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

danlivings-dxw
Copy link
Contributor

Currently Towtruck uses two JSON files for data storage, data/repos.json and data/lifetimes.json. While this is good enough for now, as Towtruck expands in functionality it will require information that is both more comprehensive and more up to date. Using JSON files as a database means that the entire file must read from or written to disk, which will introduce performance concerns as the file size and number of disk accesses increases.

This PR introduces SQLite as the data storage mechanism, which as a relational database provides several advantages over storing data in a flat file. However, as Towtruck is still in early development, the data model is still considered to be in flux, so the full advantages of having a properly normalised set of tables is not taken here. Instead, there is a single table called towtruck_data which uses a modified key-value structure. This allows the transition to gain some advantages of using a relational database, such as being able to request data only for a single repository, while retaining the flexibility of data shape originally provided by using JSON files. By retaining some of this flexibility, the refactoring to use this new data storage is relatively minor.

This will allow Towtruck to use SQLite as a relational database for data
storage instead of JSON files.
@danlivings-dxw danlivings-dxw linked an issue Sep 27, 2024 that may be closed by this pull request
@danlivings-dxw danlivings-dxw force-pushed the feature/use-sqlite-db branch 8 times, most recently from f905ed7 to 81fe697 Compare September 27, 2024 12:45
This introduces the `TowtruckDatabase` class, which serves as a wrapper
around the `Database` class in `better-sqlite3` and provides utility
methods to setup the database schema and interact with it in particular
ways.

The key-value approach serves as an intermediate step between the
current flat file database and a proper relational database - it allows
for improved querying of the data while maintaining flexibility of the
  shape of the data.
This uses the SQLite database to store both dependency lifetimes and
repo information using the key-value table in a way that introduces
minimal changes to the structure of the persisted data, which aids the
migration both for seeding and for retrieving and presenting the data.
The NODE_VERSION variable was not being correctly set, so the
`setup-node` action was defaulting to the latest LTS version (20.17.0).
This was causing `better-sqlite3` problems as it relies on native code
which does not target that version.
@danlivings-dxw danlivings-dxw force-pushed the feature/use-sqlite-db branch 4 times, most recently from 975f99f to bf6e33c Compare October 1, 2024 15:32
This will make it easier to update individual pieces of data in the
future, such as via a webhook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Iterate on data store
1 participant