mujx / hakatime

Wakatime server implementation & analytics dashboard
https://hakatime.mtx-dev.xyz
The Unlicense
611 stars 45 forks source link

unique_heartbeats does not exist #19

Closed moritz-topp closed 3 years ago

moritz-topp commented 3 years ago

Hey :D Since 2 or 3 Days my Hakatime Server won't accept any heartbeats from my IDE's. I already downloaded the docker folder and put it in my folder which bound to my postgres:11-alpine Container. But I still get this Error: [Info][02eb1eb53d12][PID 1][ThreadId 14][hakatime-0.1.0-inplace-libhaka:Haka.Heartbeats src/Haka/Heartbeats.hs:137:5] received: 1 heartbeats [Error][02eb1eb53d12][PID 1][ThreadId 14][hakatime-0.1.0-inplace-libhaka:Haka.Errors src/Haka/Errors.hs:147:5] SessionException (SessionError (QueryError "INSERT INTO heartbeats\n(\n editor,\n plugin,\n platform,\n machine,\n sender,\n user_agent,\n branch,\n category,\n cursorpos,\n dependencies,\n entity,\n is_write,\n language,\n lineno,\n file_lines,\n project,\n ty,\n time_sent\n)\n\nVALUES ( $1, $2, $3, $4, $5,\n $6, $7, $8, $9, $10,\n $11, $12, $13, CAST($14 AS INT), $15,\n $16, $17, $18 )\n\nON CONFLICT ON CONSTRAINT unique_heartbeats\nDO UPDATE SET machine=EXCLUDED.machine RETURNING id;\n" ["\"idea/2020.3.2\"","\"idea-wakatime/11.0.1\"","\"(macOS-10.16-x86_64-i386-64bit)\"","\"MacBook-Pro\"","\"moritz\"","\"wakatime/13.0.7 (macOS-10.16-x86_64-i386-64bit) Python3.8.1.final.0 idea/2020.3.2 idea-wakatime/11.0.1\"","\"master\"","null","null","[]","\"/Users/moritz/Projects/project/build.gradle\"","True","\"Groovy\"","null","61","\"project\"","file","2021-02-05 00:43:30.967000007629 UTC"] (ResultError (ServerError "42704" "constraint \"unique_heartbeats\" for table \"heartbeats\" does not exist" Nothing Nothing)))) [05/Feb/2021:00:43:37 +0000] "POST /api/v1/users/current/heartbeats.bulk HTTP/1.1" 500 - "" "wakatime/13.0.7 (macOS-10.16-x86_64-i386-64bit) Python3.8.1.final.0 idea/2020.3.2 idea-wakatime/11.0.1"

Do I have to reset my DB, or is there a way to update the DB?

If more logs or infos are required please tell me!

Thank you in advance for every bit of help :D

mujx commented 3 years ago

Hey @moritz-topp , you'll have to apply the sql files that are present in the docker/ directory. In your case you're missing this https://github.com/mujx/hakatime/blob/master/docker/004-unique-heartbeats.sql.

moritz-topp commented 3 years ago

Thank you :D I had way to much duplicates, so I decided to reset the SQL. Now I still get following error: [Info][3f837e4b60cc][PID 1][ThreadId 34][hakatime-0.1.0-inplace-libhaka:Haka.Heartbeats src/Haka/Heartbeats.hs:137:5] received: 3 heartbeats [Error][3f837e4b60cc][PID 1][ThreadId 34][hakatime-0.1.0-inplace-libhaka:Haka.Errors src/Haka/Errors.hs:147:5] UserNotFound "POST /api/v1/users/current/heartbeats.bulk HTTP/1.1" 403 - "" "wakatime/13.0.7 (macOS-10.16-x86_64-i386-64bit) Python3.8.1.final.0 idea/2020.3.2 idea-wakatime/11.0.1"

The database looks fine, but what is causing this error?

mujx commented 3 years ago

It seems that you're making an api call with an invalid api token (probably the error should have been ApiTokenWithoutUser or something like that). Probably you're using an old token before the database reset, so you'll have to create a new one and update your client.

There is also https://github.com/mujx/hakatime/blob/master/sql/delete_duplicate_heartbeats.sql which can be used to clean up duplicate heartbeats.

moritz-topp commented 3 years ago

Thank you, everything is working now!