File tree 3 files changed +17
-4
lines changed
3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 161
161
POSTGRES_EXTRA_DB_BACKEND_BASE : "django_prometheus.db.backends.postgresql" # type: ignore
162
162
163
163
# Allows to use the pgpartition command
164
- PSQLEXTRA_PARTITIONING_MANAGER = (
165
- "shared.django_apps.user_measurements.partitioning.manager"
166
- )
164
+ PSQLEXTRA_PARTITIONING_MANAGER = "shared.django_apps.partitioning.manager"
167
165
168
166
DATABASE_ROUTERS = [
169
167
"shared.django_apps.db_routers.MultiDatabaseRouter" ,
Original file line number Diff line number Diff line change 6
6
)
7
7
from psqlextra .partitioning .config import PostgresPartitioningConfig
8
8
9
+ from shared .django_apps .pg_telemetry .models import SimpleMetric
9
10
from shared .django_apps .user_measurements .models import UserMeasurement
10
11
11
12
# Overlapping partitions will cause errors - https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE -> "create partitions"
23
24
max_age = relativedelta (months = 12 ),
24
25
),
25
26
),
27
+ PostgresPartitioningConfig (
28
+ model = SimpleMetric ,
29
+ strategy = PostgresCurrentTimePartitioningStrategy (
30
+ size = PostgresTimePartitionSize (months = 1 ),
31
+ count = 3 ,
32
+ max_age = relativedelta (months = 6 ),
33
+ ),
34
+ ),
26
35
]
27
36
)
Original file line number Diff line number Diff line change 1
1
from django .conf import settings
2
2
from django .db import models
3
+ from psqlextra .models import PostgresPartitionedModel
4
+ from psqlextra .types import PostgresPartitioningMethod
3
5
4
6
5
- class BaseModel (models . Model ):
7
+ class BaseModel (PostgresPartitionedModel ):
6
8
"""
7
9
Base model for timeseries metrics. It provides a timestamp field which
8
10
represents the time that the data sample was captured at and a few metadata
@@ -13,6 +15,10 @@ class BaseModel(models.Model):
13
15
Timescale for a time, we'll pick one.
14
16
"""
15
17
18
+ class PartitioningMeta :
19
+ method = PostgresPartitioningMethod .RANGE
20
+ key = ["timestamp" ]
21
+
16
22
class Meta :
17
23
abstract = True
18
24
You can’t perform that action at this time.
0 commit comments