Skip to content

Use TimescaleDB as database for optimized time series queries #39

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

Merged
merged 17 commits into from
Jun 2, 2025

Conversation

maexled
Copy link
Owner

@maexled maexled commented Jul 20, 2024

No description provided.

@maexled maexled added the enhancement New feature or request label Jul 20, 2024
@maexled maexled self-assigned this Jul 20, 2024
@maexled maexled force-pushed the feature/timescaledb branch from 44d0533 to 667548a Compare July 20, 2024 19:48
@maexled maexled force-pushed the feature/timescaledb branch from 667548a to a109a26 Compare July 20, 2024 19:52
@maexled
Copy link
Owner Author

maexled commented Jul 20, 2024

!deploy image

Copy link

A docker image of the current pull request was deployed: ghcr.io/maexled/mystrom-django-interface:feature-timescaledb

@maexled
Copy link
Owner Author

maexled commented Jul 20, 2024

!deploy image

Copy link

A docker image of the current pull request was deployed: ghcr.io/maexled/mystrom-django-interface:feature-timescaledb

@maexled maexled force-pushed the feature/timescaledb branch from 4c790b2 to 941c6b8 Compare July 21, 2024 08:26
@maexled
Copy link
Owner Author

maexled commented Jul 21, 2024

!deploy image

Copy link

A docker image of the current pull request was deployed: ghcr.io/maexled/mystrom-django-interface:feature-timescaledb

Repository owner deleted a comment from github-actions bot Jul 21, 2024
@maexled maexled requested a review from Copilot May 29, 2025 16:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR transitions the database backend to TimescaleDB for optimized time-series queries while updating models to support composite primary keys and improving logging and code formatting.

  • Updated model definitions for MystromResult using CPkModel with composite primary keys and refined logging.
  • Adjusted tests, serializers, and forms to align with revised model and view behaviors.
  • Modified Docker, migration, and CI configurations to integrate TimescaleDB and update performance-related settings.

Reviewed Changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated no comments.

Show a summary per file
File Description
mystrom_rest/tests.py Updated tests for device creation, deletion, and result queries.
mystrom_rest/serializers.py Refactored serializers with updated quoting and formatting.
mystrom_rest/models.py Changed CPkModel usage, composite primary keys, and added logging.
mystrom_rest/migrations/* Updated migration scripts to support composite keys and hypertables.
interface/* Refactored views, URLs, tests, and forms for consistent style.
docker-compose.yml, Dockerfile Integrated TimescaleDB and adjusted resource parameters.
README.md, .env, .github/workflows/* Updated documentation and CI configurations for TimescaleDB integration.
Comments suppressed due to low confidence (3)

mystrom_rest/models.py:86

  • There is a spelling mistake in the repr output ('deivce_id' should be 'device_id').
return ("<Result(deivce_id='%s', power='%s', ws='%s', relay='%s', temperature='%s', date='%s')>" % (self.device_id, self.power, self.ws, self.relay, self.temperature, self.date))

mystrom_rest/models.py:74

  • Using primary_key=True on both the 'date' and 'device' fields is non-standard with Django's ORM. Please verify that the CPkModel integration correctly supports this composite primary key design for reliable ORM operations.
device = models.ForeignKey(MystromDevice, on_delete=models.PROTECT, primary_key=True)

Dockerfile:28

  • The increase in gunicorn's --max-requests and --max-requests-jitter settings may affect worker recycling frequency. Please ensure these values have been properly benchmarked to avoid potential stability issues under high load.
CMD ["sh", "-c", "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn --bind=0.0.0.0:8000 --timeout 300 --workers=3 --threads=3 --max-requests 20 --max-requests-jitter 5 pim.wsgi:application"]

@maexled
Copy link
Owner Author

maexled commented May 29, 2025

In Django 5.2 composite primary keys were introduced https://docs.djangoproject.com/en/5.2/topics/composite-primary-key/

@maexled maexled requested a review from Copilot May 29, 2025 19:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the database backend to use TimeScaleDB for optimized time series queries and makes minor code style and dependency updates. Key changes include:

  • A new migration that creates a hypertable for the "results" table using TimeScaleDB.
  • Adjustments in Docker configuration and documentation to support TimeScaleDB.
  • Minor updates in code formatting, tests, and dependency management.

Reviewed Changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated no comments.

Show a summary per file
File Description
mystrom_rest/migrations/0003_auto_20240720_1432.py Introduces migration steps to create a hypertable
mystrom_rest/migrations/0001_initial.py and 0002_mystromdevice_active.py Minor formatting and quoting improvements
interface/views.py, urls.py, tests.py, forms.py, apps.py Consistent quote and formatting updates
docker-compose.yml, Dockerfile Updates to Docker configuration and gunicorn parameters; adds TimescaleDB and pgadmin services
.github/workflows/*.yml, .env, .dockerignore CI and environment file adjustments for TimeScaleDB support

@maexled
Copy link
Owner Author

maexled commented May 29, 2025

!deploy image

Copy link

A docker image of the current pull request was deployed: ghcr.io/maexled/mystrom-django-interface:feature-timescaledb

@maexled maexled merged commit 4c36a4e into master Jun 2, 2025
12 checks passed
@maexled maexled deleted the feature/timescaledb branch June 2, 2025 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant