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

Add persistence layer to backend #138

Merged
merged 6 commits into from
Oct 31, 2024
Merged

Add persistence layer to backend #138

merged 6 commits into from
Oct 31, 2024

Conversation

AdrianoKF
Copy link
Collaborator

@AdrianoKF AdrianoKF commented Oct 30, 2024

Major changes

  • SQLModel with SQLite database
  • Add alembic for migrations, automatically invoked in container
  • Pydantic settings for database connection
  • Add volume for database persistence in k8s deployment
  • Bump pre-commit hooks
  • Apply some uv Docker best practices (see https://docs.astral.sh/uv/guides/integration/docker/)
  • Support file sync and hot code reload in skaffold dev (removes the need for image build and redeployment in most scenarios)

Settings

Pydantic Settings are used to control behavior of the backend (see config.py). The following settings are currently available:

  • AUTO_MIGRATE: bool controls whether Alembic migrations should be automatically applied if the database is out-of-sync
  • DB_CONNECTION_STRING: str sets the connection string used to connect to the database

These settings can be passed through environment variables of the same name.

Database Migrations

Alembic is used to perform database migrations.

As part of its entry point script, the container image automatically upgrades to the head revision (alembic upgrade head).

For local development, the AUTO_MIGRATE setting can be used to automatically run migrations on startup (or you can manually use the Alembic CLI).

Tests

The automatic db fixture in the integration test suite provides an in-memory SQLite database session.


Closes #133

- SQLModel with SQLite database
- Add alembic for migrations, automatically invoked in container
- Pydantic settings for database connection
- Add volume for database persistence in k8s deployment
- Bump pre-commit hooks
@AdrianoKF AdrianoKF self-assigned this Oct 30, 2024
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 73.56322% with 23 lines in your changes missing coverage. Please review.

Project coverage is 57.34%. Comparing base (ff36c96) to head (09fd9b7).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
backend/src/jobq_server/__main__.py 45.00% 11 Missing ⚠️
backend/src/jobq_server/alembic/env.py 80.76% 5 Missing ⚠️
backend/src/jobq_server/db.py 81.48% 5 Missing ⚠️
backend/src/jobq_server/dependencies/__init__.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #138      +/-   ##
==========================================
+ Coverage   56.92%   57.34%   +0.42%     
==========================================
  Files          63       66       +3     
  Lines        3164     3247      +83     
==========================================
+ Hits         1801     1862      +61     
- Misses       1363     1385      +22     
Flag Coverage Δ
backend 86.51% <73.56%> (-1.68%) ⬇️
client 48.92% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AdrianoKF AdrianoKF linked an issue Oct 30, 2024 that may be closed by this pull request
@AdrianoKF AdrianoKF merged commit 7dcdb6a into main Oct 31, 2024
4 checks passed
@AdrianoKF AdrianoKF deleted the 133-persistence branch October 31, 2024 09:24
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.

Set up persistence layer in backend
1 participant