blob: b31324f083aa763812b9813aa7a604b3240579b1 [file] [log] [blame]
Serge Bazanski35e8d792022-10-11 11:32:30 +02001CREATE TABLE machines (
2 machine_id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
3 machine_created_at TIMESTAMPTZ NOT NULL
4);
5
6
7-- Sessions are maintained by components as they work on the rest of the machine
8-- database. Once a session is created, it must be maintained by its owning
9-- component by repeatedly 'poking' it, ie. updating the heartbeat_deadline
10-- value to be some point in the future.
11--
12-- TODO: garbage collect old sessions.
13CREATE TABLE sessions (
14 session_id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
15 -- Name of component which created this session. Human-readable.
16 session_component_name STRING NOT NULL,
17 -- Node name, hostname:port, pod name, whatever. Something to tell where
18 -- a particular component is running. Human-readable.
19 session_runtime_info STRING NOT NULL,
20 -- Time at which this session was created.
21 session_created_at TIMESTAMPTZ NOT NULL,
22 -- Number of seconds by which session_deadline (counting from now())
23 -- is bumped up every time the session is poked.
24 session_interval_seconds INT NOT NULL,
25 -- Deadline after which this session should not be considered valid anymore.
26 session_deadline TIMESTAMPTZ NOT NULL
27);
28
29CREATE TYPE process AS ENUM (
30 -- Reserved for unit tests.
31 'UnitTest1',
32 'UnitTest2'
33);
34
35-- Work items map a session to work performed on a machine. Multiple work items
36-- can exist per session, and thus, a session can back multiple items of work
37-- acting on multiple machines. These are optionally created by components to
38-- indicate some long-running process being performed on a machine, and will
39-- lock out the same process from being run simultaneously, eg. in a
40-- concurrently running instance of the same component.
41CREATE TABLE work (
42 -- Machine that this work is being performed on. Prevent deleting machines
43 -- that have active work on them.
44 machine_id UUID NOT NULL REFERENCES machines(machine_id) ON DELETE RESTRICT,
45 -- Session that this work item is tied to. If the session expires, so does
46 -- the work item.
47 session_id UUID NOT NULL REFERENCES sessions(session_id) ON DELETE CASCADE,
48 -- Human-readable process name.
49 process process NOT NULL,
50 UNIQUE (machine_id, process),
51 CONSTRAINT "primary" PRIMARY KEY (machine_id, session_id, process)
52);
53
54-- The following three tables are for illustrative purposes only.
55
56CREATE TABLE machine_provided (
57 machine_id UUID NOT NULL REFERENCES machines(machine_id) ON DELETE CASCADE,
58 provider STRING NOT NULL,
59 provider_id STRING NOT NULL,
60 CONSTRAINT "primary" PRIMARY KEY (machine_id)
61);
62
63CREATE TABLE machine_agent_installed (
64 machine_id UUID NOT NULL REFERENCES machines(machine_id) ON DELETE CASCADE,
65 CONSTRAINT "primary" PRIMARY KEY (machine_id)
66);
67
68CREATE TABLE machine_agent_report (
69 machine_id UUID NOT NULL REFERENCES machines(machine_id) ON DELETE CASCADE,
70 shape_cpu_count INT NOT NULL,
71 shape_memory_megabytes INT NOT NULL,
72 CONSTRAINT "primary" PRIMARY KEY (machine_id)
73);