waveterm/wavesrv/db/migrations/000027_historyupdates.up.sql
Mike Sawka 2f7cce294c
big update to screen/session delete, and clear (#199)
* sync schema.sql with running schema

* remove incognito field from history table. also don't add empty FeState vars

* history updates, add festate, durationms, exitcode, status, and tags into history table

* update screen/session delete, and clear to no longer purge history items.  move deleted screens/sessions into a tombstone table.

* update schema

* fix alias -> fn

* quiet the security warning about an unchecked byte conversion. no real security issue here, but add a range check for good measure.
2023-12-27 13:11:53 -08:00

40 lines
1.1 KiB
SQL

ALTER TABLE history DROP COLUMN incognito;
ALTER TABLE history ADD COLUMN exitcode int NULL DEFAULT NULL;
ALTER TABLE history ADD COLUMN durationms int NULL DEFAULT NULL;
ALTER TABLE history ADD COLUMN festate json NOT NULL DEFAULT '{}';
ALTER TABLE history ADD COLUMN tags json NOT NULL DEFAULT '{}';
ALTER TABLE history ADD COLUMN status varchar(10) NOT NULL DEFAULT 'unknown';
UPDATE cmd
SET festate = json_remove(festate, "$.PROMPTVAR_GITBRANCH")
WHERE festate->>'PROMPTVAR_GITBRANCH' = '';
UPDATE history
SET exitcode = cmd.exitcode,
durationms = cmd.durationms,
festate = cmd.festate,
status = cmd.status
FROM cmd
WHERE history.screenid = cmd.screenid
AND history.lineid = cmd.lineid;
UPDATE history
SET status = 'done'
WHERE lineid = '';
CREATE TABLE session_tombstone (
sessionid varchar(36) PRIMARY KEY,
deletedts bigint NOT NULL,
name varchar(50) NOT NULL
);
CREATE TABLE screen_tombstone (
screenid varchar(36) PRIMARY KEY,
sessionid varchar(36) NOT NULL,
deletedts bigint NOT NULL,
screenopts json NOT NULL,
name varchar(50) NOT NULL
);