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:
parent
a922801690
commit
346b063f45
34
src/migrations/20251009132935-add-edge-node-presence.js
Normal file
34
src/migrations/20251009132935-add-edge-node-presence.js
Normal 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,
|
||||
);
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user