Skip to content

Commit a068fcd

Browse files
add indices
1 parent 0cd3038 commit a068fcd

8 files changed

Lines changed: 574 additions & 89 deletions

File tree

dojo/auditlog.py

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from auditlog.registry import auditlog
1313
from django.conf import settings
1414
from django.core.management import call_command
15+
from django.db import models
1516

1617
logger = logging.getLogger(__name__)
1718

@@ -128,70 +129,140 @@ def register_django_pghistory_models():
128129
pghistory.DeleteEvent(),
129130
pghistory.ManualEvent(label="initial_import"),
130131
exclude=["password"],
132+
# add some indexes manually so we don't have to define a customer phistory Event model with overridden fields.
133+
meta={
134+
"indexes": [
135+
models.Index(fields=["pgh_created_at"]),
136+
models.Index(fields=["pgh_label"]),
137+
models.Index(fields=["pgh_context_id"]),
138+
],
139+
},
131140
)(Dojo_User)
132141

133-
# Track other models
134142
pghistory.track(
135143
pghistory.InsertEvent(),
136144
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
137145
pghistory.DeleteEvent(),
138146
pghistory.ManualEvent(label="initial_import"),
147+
meta={
148+
"indexes": [
149+
models.Index(fields=["pgh_created_at"]),
150+
models.Index(fields=["pgh_label"]),
151+
models.Index(fields=["pgh_context_id"]),
152+
],
153+
},
139154
)(Endpoint)
140155

141156
pghistory.track(
142157
pghistory.InsertEvent(),
143158
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
144159
pghistory.DeleteEvent(),
145160
pghistory.ManualEvent(label="initial_import"),
161+
meta={
162+
"indexes": [
163+
models.Index(fields=["pgh_created_at"]),
164+
models.Index(fields=["pgh_label"]),
165+
models.Index(fields=["pgh_context_id"]),
166+
],
167+
},
146168
)(Engagement)
147169

148170
pghistory.track(
149171
pghistory.InsertEvent(),
150172
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
151173
pghistory.DeleteEvent(),
152174
pghistory.ManualEvent(label="initial_import"),
175+
meta={
176+
"indexes": [
177+
models.Index(fields=["pgh_created_at"]),
178+
models.Index(fields=["pgh_label"]),
179+
models.Index(fields=["pgh_context_id"]),
180+
],
181+
},
153182
)(Finding)
154183

155184
pghistory.track(
156185
pghistory.InsertEvent(),
157186
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
158187
pghistory.DeleteEvent(),
159188
pghistory.ManualEvent(label="initial_import"),
189+
meta={
190+
"indexes": [
191+
models.Index(fields=["pgh_created_at"]),
192+
models.Index(fields=["pgh_label"]),
193+
models.Index(fields=["pgh_context_id"]),
194+
],
195+
},
160196
)(Finding_Group)
161197

162198
pghistory.track(
163199
pghistory.InsertEvent(),
164200
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
165201
pghistory.DeleteEvent(),
166202
pghistory.ManualEvent(label="initial_import"),
203+
meta={
204+
"indexes": [
205+
models.Index(fields=["pgh_created_at"]),
206+
models.Index(fields=["pgh_label"]),
207+
models.Index(fields=["pgh_context_id"]),
208+
],
209+
},
167210
)(Product_Type)
168211

169212
pghistory.track(
170213
pghistory.InsertEvent(),
171214
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
172215
pghistory.DeleteEvent(),
173216
pghistory.ManualEvent(label="initial_import"),
217+
meta={
218+
"indexes": [
219+
models.Index(fields=["pgh_created_at"]),
220+
models.Index(fields=["pgh_label"]),
221+
models.Index(fields=["pgh_context_id"]),
222+
],
223+
},
174224
)(Product)
175225

176226
pghistory.track(
177227
pghistory.InsertEvent(),
178228
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
179229
pghistory.DeleteEvent(),
180230
pghistory.ManualEvent(label="initial_import"),
231+
meta={
232+
"indexes": [
233+
models.Index(fields=["pgh_created_at"]),
234+
models.Index(fields=["pgh_label"]),
235+
models.Index(fields=["pgh_context_id"]),
236+
],
237+
},
181238
)(Test)
182239

183240
pghistory.track(
184241
pghistory.InsertEvent(),
185242
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
186243
pghistory.DeleteEvent(),
187244
pghistory.ManualEvent(label="initial_import"),
245+
meta={
246+
"indexes": [
247+
models.Index(fields=["pgh_created_at"]),
248+
models.Index(fields=["pgh_label"]),
249+
models.Index(fields=["pgh_context_id"]),
250+
],
251+
},
188252
)(Risk_Acceptance)
189253

190254
pghistory.track(
191255
pghistory.InsertEvent(),
192256
pghistory.UpdateEvent(condition=pghistory.AnyChange(exclude_auto=True)),
193257
pghistory.DeleteEvent(),
194258
pghistory.ManualEvent(label="initial_import"),
259+
meta={
260+
"indexes": [
261+
models.Index(fields=["pgh_created_at"]),
262+
models.Index(fields=["pgh_label"]),
263+
models.Index(fields=["pgh_context_id"]),
264+
],
265+
},
195266
)(Finding_Template)
196267

197268
pghistory.track(
@@ -200,6 +271,13 @@ def register_django_pghistory_models():
200271
pghistory.DeleteEvent(),
201272
pghistory.ManualEvent(label="initial_import"),
202273
exclude=["password"],
274+
meta={
275+
"indexes": [
276+
models.Index(fields=["pgh_created_at"]),
277+
models.Index(fields=["pgh_label"]),
278+
models.Index(fields=["pgh_context_id"]),
279+
],
280+
},
203281
)(Cred_User)
204282

205283
pghistory.track(
@@ -208,6 +286,13 @@ def register_django_pghistory_models():
208286
pghistory.DeleteEvent(),
209287
pghistory.ManualEvent(label="initial_import"),
210288
exclude=["header_name", "header_value"],
289+
meta={
290+
"indexes": [
291+
models.Index(fields=["pgh_created_at"]),
292+
models.Index(fields=["pgh_label"]),
293+
models.Index(fields=["pgh_context_id"]),
294+
],
295+
},
211296
)(Notification_Webhooks)
212297

213298
# Only log during actual application startup, not during shell commands

0 commit comments

Comments
 (0)