-
Notifications
You must be signed in to change notification settings - Fork 1.3k
WIP: Implement db model in go #8967
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
Conversation
@easyCZ: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
Prototype implementation of DB acccess model in go
Model code-generation
Initial model generation can be done automatically with
which will reflect over the table and generate a model, super handy. However, manual adjustments need to be made to apply our custom transformers and custom data type handling.
Custom data types
In many places, we use custom data types with transformers. Below is a rough summary of how to deal with these.
Varchar with a ISO 8601 timestamp
This one is a bit nasty, as it doesn't use the native datetime type so GORM can't do automatic inference. We use it primary for
creationTime
fields (lastModified
use DATETIME). However, we can deal with this by typing our custom timestamp fields appropriately. SeeVarcharTime
implementation.Simple JSON column
This one can be addressed as a combination of existing GORM JSON data type extensions, and pointer field which makes it nullable. Using
gorm.io/datatypes
has the nice benefit of getting access to JsonPath extractors which allow us to query the JSON structure slightly better.Empty String to Undefined
Again, can be solved with a custom type alias which implements the
Scanner
andValuer
interfaces.UUIDs
Using
github.com/google/uuid
makes UUIDs work out of the box for us.Encrypted fields
We can extend fields to be encrypted when serialised and deserialized using https://gorm.io/docs/data_types.html#Value-based-on-Context
Related Issue(s)
Fixes #
How to test
k port-forward mysql-0 3306:3306
cd components/gitpod-db-go && go test ./...
Release Notes
Documentation
/uncc