feat: add created_at/updated_at columns to cluster and machines store tables

This commit is contained in:
Pasha Sviderski
2026-05-26 10:07:12 +10:00
parent 7616f1365a
commit 26951773d1
2 changed files with 24 additions and 13 deletions
+15 -10
View File
@@ -1,31 +1,36 @@
-- cluster table stores the key-value pairs of the cluster configuration.
CREATE TABLE cluster
(
key TEXT NOT NULL PRIMARY KEY,
value ANY
key TEXT NOT NULL PRIMARY KEY,
value ANY,
-- updated_at is the last time the value was written.
updated_at TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00'
);
-- machines table stores the basic information of the machines in the cluster.
CREATE TABLE machines
(
id TEXT NOT NULL PRIMARY KEY,
name TEXT AS (json_extract(info, '$.name')),
id TEXT NOT NULL PRIMARY KEY,
name TEXT AS (json_extract(info, '$.name')),
-- info is a JSON-serialized MachineInfo protobuf message.
info TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(info))
-- TODO: add created_at and updated_at fields to track machine age and last update time.
info TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(info)),
-- created_at is the time the machine record was created.
created_at TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00',
-- updated_at is the last time the machine record was updated.
updated_at TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00'
);
-- containers table stores the Uncloud-managed Docker containers created in the cluster.
CREATE TABLE containers
(
id TEXT NOT NULL PRIMARY KEY,
id TEXT NOT NULL PRIMARY KEY,
-- container is a JSON-serialized api.ServiceContainer struct.
container TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(container)),
machine_id TEXT NOT NULL DEFAULT '',
container TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(container)),
machine_id TEXT NOT NULL DEFAULT '',
service_id TEXT AS (json_extract(container, '$.Config.Labels."uncloud.service.id"')),
service_name TEXT AS (json_extract(container, '$.Config.Labels."uncloud.service.name"')),
-- sync_status indicates if the record reflects the actual Docker state of the container.
sync_status TEXT NOT NULL DEFAULT '',
sync_status TEXT NOT NULL DEFAULT '',
-- updated_at is the last time the record was updated.
updated_at TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00'
);