Allow import-json to import custom columns (#282)

* Allow import-json to import custom columns

* Add tests
This commit is contained in:
David Dworken 2025-01-13 14:55:59 -07:00 committed by GitHub
parent 4c696d9788
commit 2f3201ec81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 4 deletions

View File

@ -3454,6 +3454,8 @@ func TestExportJson(t *testing.T) {
db := hctx.GetDb(hctx.MakeContext())
e1 := testutils.MakeFakeHistoryEntry("echo synth1")
e1.StartTime = time.Unix(1234567, 0)
e1.CustomColumns = make(data.CustomColumns, 1)
e1.CustomColumns[0] = data.CustomColumn{Name: "MyCol", Val: "bar"}
require.NoError(t, db.Create(e1).Error)
e2 := testutils.MakeFakeHistoryEntry("echo synth2")
e1.StartTime = time.Unix(1244567, 0)

View File

@ -77,9 +77,6 @@ func importFromJson(ctx context.Context) (int, error) {
if entry.Command == "" {
return 0, fmt.Errorf("cannot import history entries without a command, JSON line: %#v", line)
}
if len(entry.CustomColumns) > 0 {
return 0, fmt.Errorf("cannot import history entries with custom columns, JSON line: %#v", line)
}
if entry.LocalUsername == "" {
entry.LocalUsername = currentUser.Username
}

View File

@ -1,2 +1,2 @@
{"command":"echo synth2","current_working_directory":"/tmp/","custom_columns":null,"end_time":"2022-10-18T04:43:24Z","exit_code":2,"home_directory":"/home/david/","hostname":"localhost","local_username":"david","start_time":"2022-10-18T04:43:21Z"}
{"command":"echo synth1","current_working_directory":"/tmp/","custom_columns":null,"end_time":"2022-10-18T04:43:19Z","exit_code":2,"home_directory":"/home/david/","hostname":"localhost","local_username":"david","start_time":"1970-01-14T22:56:07-08:00"}
{"command":"echo synth1","current_working_directory":"/tmp/","custom_columns":[{"name":"MyCol","value":"bar"}],"end_time":"2022-10-18T04:43:19Z","exit_code":2,"home_directory":"/home/david/","hostname":"localhost","local_username":"david","start_time":"1970-01-14T22:56:07-08:00"}