-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add mssql support #592
Add mssql support #592
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this contribution and for diving into the depths of all of this! 🙌 I did a bunch of quick tests myself with MSSQL and from what I found, everything is working like a charm!
Only when running the API tests against SQLite, I'm getting a bunch of errors, including 500 responses for the metrics- and WakaTime projects-endpoints.
Let me know when you want me to go for another round of review! |
Thanks for your review. Definitely! I focused only on the mssql functionalities in the last few days. I will try with other dbs and fix the problems. Some problems seem to be pretty annoying, especially the foreign key constraint one. It may take a few days to fix all of these. |
Hello, I think it's now ready for another review. |
Very cool, thank you so much! Only found one last issue. Every heartbeat has a Try inserting the same heartbeat twice in a row: curl --location 'http://localhost:3000/api/heartbeat' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <YOUR-BASE64-HASHED-API-KEY>' \
--data '[{
"entity": "/home/user1/dev/project1/main.go",
"project": "wakapi",
"language": "Go",
"is_write": true,
"type": "file",
"category": null,
"branch": null,
"time": 1705342578.955
}]' Both requests should result in a
Any ideas how to work around this? |
It is because of a bug in sqlserver dialector. An issue for it has been opened for a long time, but have not got response from gorm authors yet. I tried to fix it (attempted fix commit) but it didn't work, and the problem seems too complicated. The root cause is sqlserver doesn't support Current workaround is that all heartbeats will be inserted one by one, and errors caused by duplicate hash will be ignored. It guarantees correctness but impacts performance. Considering most of time only one heartbeat will be inserted at once, I think the performance penalty should be acceptable. Another alternative approach is to write raw sql just for mssql. Although there are a lot of ways to emulate the behavior ( |
Thanks a lot for the detailed explanation and for the fix. I think it's very reasonable as a workaround. Again: 🙏 🙌. |
I'll let the code run in production for a short while and push out a new release soon if no errors pop up (likely tomorrow or so). |
Fixes #591.
Notes on MSSQL:
update table as t set xxx = xxx
,as t
is invalidusers
)utils.QuoteDbIdentifiers
andutils.QuoteSql
functions to quote identifiers in SQLs in any dialectorsdatetimeoffset
instead oftimestamp
for datetime when modeling.CustomTime
for datetime properties/columns and don't specify type using tag.CustomTime
will choose correct type for all dbsjoin using
join on
insteadTested functionalities:
Get "https://api.wakatime.com/api/v1/users/current/data_dumps": unexpected EOF
. seems not related to db.