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

models: fix EventRecord default saved_at timestamp type #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
-------------------

- Aggregator field on the Application admin was wrongly required.
- Fix default `saved_at` for event records
Copy link
Contributor

Choose a reason for hiding this comment

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

You're not in par with the latest master.



0.6.14 (2019-10-18)
Expand Down
18 changes: 18 additions & 0 deletions mds/migrations/0057_pre_event_record_auto_now.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.5 on 2019-10-23 14:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mds', '0056_post_compliance_saved_at_not_nullable'),
]

operations = [
migrations.AlterField(
model_name='eventrecord',
name='saved_at',
field=models.DateTimeField(auto_now=True, db_index=True),
),
]
Copy link
Contributor

Choose a reason for hiding this comment

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

AlterField migrations are post-deploy.

4 changes: 1 addition & 3 deletions mds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django import forms
from django.contrib.gis.db import models as gis_models
from django.contrib.postgres import fields as pg_fields
from django.contrib.postgres import functions as pg_functions
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Count, Prefetch, Q
Expand Down Expand Up @@ -248,8 +247,7 @@ def gps_point_as_geojson(self):
class EventRecord(models.Model):
timestamp = models.DateTimeField(db_index=True)
point = gis_models.PointField(blank=True, null=True)
# For synchronisation purposes (polling on this field)
saved_at = models.DateTimeField(default=pg_functions.TransactionNow, db_index=True)
saved_at = models.DateTimeField(auto_now=True, db_index=True)
# For KPIs, know when the event was seen by an aggregator the first time
first_saved_at = models.DateTimeField(blank=True, null=True)
source = UnboundedCharField(
Expand Down