Coverage for downtify/db/migrations/schema/activity.py: 100%

2 statements  

« prev     ^ index     » next       coverage.py v7.17.4, created at 2026-11-21 22:18 +0000

1"""Postgres DDL for the activity log and the traffic counters. 

2 

3``activity`` lives in the activity database 

4(:class:`downtify.activity.ActivityLog`). ``traffic_counters`` is written by 

5:class:`downtify.traffic.TrafficCounters` into the library database 

6(``downtify_library.db``), not the activity database; it is grouped here 

7because both are per-user usage history. 

8""" 

9 

10from __future__ import annotations 

11 

12DDL: list[str] = [ 

13 """ 

14 CREATE TABLE IF NOT EXISTS activity ( 

15 id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, 

16 at TEXT NOT NULL, 

17 user_id BIGINT NOT NULL DEFAULT 0, 

18 username TEXT NOT NULL DEFAULT '', 

19 kind TEXT NOT NULL, 

20 summary TEXT NOT NULL DEFAULT '', 

21 detail_json TEXT NOT NULL DEFAULT '{}', 

22 client TEXT NOT NULL DEFAULT '', 

23 ip TEXT NOT NULL DEFAULT '' 

24 ) 

25 """, 

26 """ 

27 CREATE INDEX IF NOT EXISTS activity_user 

28 ON activity (user_id, id) 

29 """, 

30 """ 

31 CREATE TABLE IF NOT EXISTS traffic_counters ( 

32 user_id BIGINT NOT NULL, 

33 direction TEXT NOT NULL, 

34 total_bytes BIGINT NOT NULL DEFAULT 0, 

35 updated_at TEXT NOT NULL, 

36 PRIMARY KEY (user_id, direction) 

37 ) 

38 """, 

39]