1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-27 11:02:16 +01:00

chore: add migration for tracking connected downstream edge nodes (#10765)

https://linear.app/unleash/issue/2-3938/endpoint-in-unleash-edge-validate-license

Database migration for a new `edge_node_presence` table and
`bucket_edge_heartbeat` function.
This commit is contained in:
Simon Hornby 2025-10-09 15:38:07 +02:00 committed by GitHub
parent a922801690
commit 346b063f45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,34 @@
exports.up = function(db, cb) {
db.runSql(
`
CREATE OR REPLACE FUNCTION bucket_edge_heartbeat(ts timestamptz)
RETURNS timestamptz
LANGUAGE SQL IMMUTABLE PARALLEL SAFE AS $$
SELECT to_timestamp(floor(extract(epoch FROM ts) / 300) * 300) AT TIME ZONE 'UTC';
$$;
CREATE TABLE edge_node_presence (
bucket_ts timestamptz NOT NULL,
node_ephem_id text NOT NULL,
PRIMARY KEY (bucket_ts, node_ephem_id)
);
CREATE INDEX edge_node_presence_brin ON edge_node_presence USING BRIN (bucket_ts);
CREATE INDEX edge_node_presence_node_hash ON edge_node_presence USING HASH (node_ephem_id);
`,
cb,
);
};
exports.down = function(db, cb) {
db.runSql(
`
DROP INDEX IF EXISTS edge_node_presence_brin;
DROP INDEX IF EXISTS edge_node_presence_node_hash;
DROP TABLE IF EXISTS edge_node_presence;
DROP FUNCTION IF EXISTS bucket_edge_heartbeat(timestamptz);
`,
cb,
);
};