-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathschema.sql
47 lines (41 loc) · 1.25 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
BEGIN;
--
-- A relation that allows consumers to track what they last consumed from the
-- stream.
--
CREATE TABLE checkpoints (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
last_redis_id TEXT NOT NULL,
last_ride_id BIGINT NOT NULL
);
--
-- A relation that tracks some state that consumers are tracking as they
-- consume the stream. In this case we're tracking the total distance of all
-- rides that have been initiated on the service. Consumers may update their
-- state at different times, but for any given checkpoint ID, they should
-- always show the same total.
--
CREATE TABLE consumer_states (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
total_distance DOUBLE PRECISION NOT NULL
);
--
-- A relation representing a single ride by a user.
--
CREATE TABLE rides (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
distance DOUBLE PRECISION NOT NULL
);
--
-- A relation that holds our transactionally-staged log records.
--
CREATE TABLE staged_log_records (
id BIGSERIAL PRIMARY KEY,
action TEXT NOT NULL,
data JSONB NOT NULL,
object TEXT NOT NULL
);
COMMIT;