0.1.52 Gateway
This commit is contained in:
@@ -57,6 +57,27 @@ CREATE TABLE IF NOT EXISTS device_versions (
|
||||
CREATE INDEX IF NOT EXISTS device_versions_recent_idx
|
||||
ON device_versions (device_id, last_seen_at DESC);
|
||||
|
||||
-- One row per television per day it was used.
|
||||
--
|
||||
-- It exists to answer "is this the first time this set has opened Memby today", which is
|
||||
-- a question a counter or a timestamp cannot answer safely: every television in the house
|
||||
-- asks at once, so the answer has to come from the insert itself. The primary key is what
|
||||
-- makes it atomic — the row either went in, which means first, or it did not.
|
||||
--
|
||||
-- The day is the *household's* local day, computed against MEMBY_TIMEZONE and stored as a
|
||||
-- plain date, because "today" is a thing the people watching have an opinion about and
|
||||
-- UTC does not agree with it for most of a New Zealand evening.
|
||||
CREATE TABLE IF NOT EXISTS device_activity_days (
|
||||
device_id TEXT NOT NULL,
|
||||
emby_user_id TEXT NOT NULL,
|
||||
day DATE NOT NULL,
|
||||
first_seen_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (device_id, emby_user_id, day)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS device_activity_days_day_idx
|
||||
ON device_activity_days (day);
|
||||
|
||||
-- The imported library.
|
||||
--
|
||||
-- payload is Emby's item JSON verbatim, so rows served from here are byte-identical to
|
||||
|
||||
Reference in New Issue
Block a user