Skip to content

Commit

Permalink
add partitioning to pg_telemetry SimpleMetric model
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-codecov committed Jun 6, 2024
1 parent bf76a73 commit a012988
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shared/django_apps/db_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@

# Allows to use the pgpartition command
PSQLEXTRA_PARTITIONING_MANAGER = (
"shared.django_apps.user_measurements.partitioning.manager"
"shared.django_apps.partitioning.manager"
)

DATABASE_ROUTERS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)
from psqlextra.partitioning.config import PostgresPartitioningConfig

from shared.django_apps.pg_telemetry.models import SimpleMetric
from shared.django_apps.user_measurements.models import UserMeasurement

# Overlapping partitions will cause errors - https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE -> "create partitions"
Expand All @@ -23,5 +24,13 @@
max_age=relativedelta(months=12),
),
),
PostgresPartitioningConfig(
model=SimpleMetric,
strategy=PostgresCurrentTimePartitioningStrategy(
size=PostgresTimePartitionSize(months=1),
count=3,
max_age=relativedelta(months=6),
),
),
]
)
8 changes: 7 additions & 1 deletion shared/django_apps/pg_telemetry/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.conf import settings
from django.db import models
from psqlextra.models import PostgresPartitionedModel
from psqlextra.types import PostgresPartitioningMethod


class BaseModel(models.Model):
class BaseModel(PostgresPartitionedModel):
"""
Base model for timeseries metrics. It provides a timestamp field which
represents the time that the data sample was captured at and a few metadata
Expand All @@ -13,6 +15,10 @@ class BaseModel(models.Model):
Timescale for a time, we'll pick one.
"""

class PartitioningMeta:
method = PostgresPartitioningMethod.RANGE
key = ["timestamp"]

class Meta:
abstract = True

Expand Down

0 comments on commit a012988

Please sign in to comment.