Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/worklog/store: fix timestamp and datastr column types #111

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cmd/worklog/store/db.go
Original file line number Diff line number Diff line change
@@ -207,17 +207,17 @@ create table if not exists buckets (
type TEXT NOT NULL,
client TEXT NOT NULL,
hostname TEXT NOT NULL,
created TEXT NOT NULL, -- unix micro
datastr TEXT NOT NULL -- JSON text
);
created TEXT NOT NULL, -- RFC3339 nano
datastr BLOB NOT NULL -- JSON text
) STRICT;
create table if not exists events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bucketrow INTEGER NOT NULL,
starttime INTEGER NOT NULL, -- unix micro
endtime INTEGER NOT NULL, -- unix micro
datastr TEXT NOT NULL, -- JSON text
starttime TEXT NOT NULL, -- RFC3339 nano
endtime TEXT NOT NULL, -- RFC3339 nano
datastr BLOB NOT NULL, -- JSON text
FOREIGN KEY (bucketrow) REFERENCES buckets(rowid)
);
) STRICT;
create index if not exists event_index_id ON events(id);
create index if not exists event_index_starttime ON events(bucketrow, starttime);
create index if not exists event_index_endtime ON events(bucketrow, endtime);
@@ -790,14 +790,14 @@ func (db *DB) Select(query string) ([]map[string]any, error) {

const AmendEvents = `begin transaction;
-- ensure we have an amend array.
update events set datastr = json_insert(datastr, '$.amend', json('[]'))
update events set datastr = cast(json_insert(datastr, '$.amend', json('[]')) as BLOB)
where
datetime(starttime, 'subsec') < datetime(?5, 'subsec') and
datetime(endtime, 'subsec') > datetime(?4, 'subsec') and
bucketrow = (
select rowid from buckets where id = ?1
);
update events set datastr = json_insert(datastr, '$.amend[#]', json_object('time', ?2, 'msg', ?3, 'replace', (
update events set datastr = cast(json_insert(datastr, '$.amend[#]', json_object('time', ?2, 'msg', ?3, 'replace', (
-- trim amendments down to original event bounds.
select json_group_array(json_replace(value,
'$.start', case
@@ -818,7 +818,7 @@ const AmendEvents = `begin transaction;
where
datetime(json_extract(value, '$.start'), 'subsec') < datetime(endtime, 'subsec') and
datetime(json_extract(value, '$.end'), 'subsec') > datetime(starttime, 'subsec')
)))
))) as BLOB)
where
datetime(starttime, 'subsec') < datetime(?5, 'subsec') and
datetime(endtime, 'subsec') > datetime(?4, 'subsec') and