fix: VisitSession 时间戳恢复 NOT NULL,测试补显式时间(修正计划的测试笔误)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-15 11:46:51 +08:00
parent 79f2a89e0a
commit 462852c3f3
3 changed files with 7 additions and 7 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
# Generated by Django 5.2.17 on 2026-09-15 03:44
# Generated by Django 5.2.17 on 2026-09-15 03:46
import django.db.models.deletion
import tracker.models
@@ -65,8 +65,8 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('session_id', models.CharField(max_length=64)),
('started_at', models.DateTimeField(blank=True, null=True)),
('ended_at', models.DateTimeField(blank=True, null=True)),
('started_at', models.DateTimeField()),
('ended_at', models.DateTimeField()),
('referrer_domain', models.CharField(blank=True, default='', max_length=200)),
('utm', models.JSONField(blank=True, default=dict)),
('landing_path', models.CharField(blank=True, default='', max_length=500)),
+2 -3
View File
@@ -56,9 +56,8 @@ class VisitSession(models.Model):
site = models.ForeignKey(Site, on_delete=models.CASCADE, related_name="sessions")
visitor = models.ForeignKey(Visitor, on_delete=models.CASCADE, related_name="sessions")
session_id = models.CharField(max_length=64)
# null=True:会话可先建行后回填时间(ended_at 为空表示会话进行中)
started_at = models.DateTimeField(null=True, blank=True)
ended_at = models.DateTimeField(null=True, blank=True)
started_at = models.DateTimeField()
ended_at = models.DateTimeField()
referrer_domain = models.CharField(max_length=200, blank=True, default="")
utm = models.JSONField(default=dict, blank=True)
landing_path = models.CharField(max_length=500, blank=True, default="")
+2 -1
View File
@@ -18,7 +18,8 @@ def test_visitor_first_touch_fields():
def test_event_unique_site_event_id():
site = Site.objects.create(name="s", domains=["a.com"])
v = Visitor.objects.create(site=site, visitor_id="vid1")
s = VisitSession.objects.create(site=site, visitor=v, session_id="sid1")
s = VisitSession.objects.create(site=site, visitor=v, session_id="sid1",
started_at="2026-09-15T10:00:00Z", ended_at="2026-09-15T10:01:00Z")
Event.objects.create(site=site, visitor=v, session=s, event_id="e1",
event_name="page_view", occurred_at="2026-09-15T10:00:00Z", path="/")
with pytest.raises(Exception):