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

[usage] Add db.WorkspaceInstance model in golang #10367

Merged
merged 1 commit into from
Jun 2, 2022
Merged

Conversation

easyCZ
Copy link
Member

@easyCZ easyCZ commented May 31, 2022

Description

Same as #10293 but for WorkspaceInstances.

Related Issue(s)

How to test

Unit tests

Release Notes

NONE

Documentation

NONE

@easyCZ
Copy link
Member Author

easyCZ commented Jun 1, 2022

/hold

@easyCZ easyCZ requested a review from a team June 1, 2022 07:23
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Jun 1, 2022
@geropl geropl self-assigned this Jun 1, 2022

type WorkspaceInstance struct {
ID uuid.UUID `gorm:"primary_key;column:id;type:char;size:36;" json:"id"`
WorkspaceID string `gorm:"column:workspaceId;type:char;size:36;" json:"workspaceId"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: one ID column is UUID, the other string: Why not make both strings? (so far we only have one column type for IDs: string) What's the advantange of UUID?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workspace Instance ID is an actual UUID, but Workspace ID is something like org-repo-random-string which isn't a valid UUID

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUID allows you to parse UUIDs and validate before you even hit the DB. UUID is the more appropriate type as it's more specific. For example, it prevents you from inserting something like Workspace{ID: "my-random-string"} because it won't even compile

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse UUIDs and validate before you even hit the DB

Jup. My point was that it's the only point in the code that imposes that constraint, then. The only constraint we have so far is "equality".

Mentioning this to a) raise awareness and b) to think about how we see this DB layer. So far I thought about it as 100% follower of the primary implementation we have.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it is. uuid.UUID serializes as a string. It's the same as using the UUID_COLUMN type in our TypeORM implementation.

https://github.com/gitpod-io/gitpod/blob/main/components/gitpod-db/src/typeorm/entity/db-workspace-instance.ts#L24

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! The UUID_COLUMN_TYPE is only there to ensure the width/type of the field is the same everywhere.

The key question is: does uuid.UUID influence the runtime behavior (e.g., introduces new error modes during parsing? If no I'm happy! 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't, as long as what is stored in the DB is a valid UUID. I'm gonna run it against the RO replica of staging & prod to batch list all items to validate we don't have underlying violations to verify.

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good, tests are green! ✔️

/hold because of this question. I leave it up to you to handle. 🙏

Base automatically changed from mp/usage-db-varchartime to main June 2, 2022 12:49
@roboquat roboquat added size/XL and removed size/L labels Jun 2, 2022
@easyCZ
Copy link
Member Author

easyCZ commented Jun 2, 2022

/unhold

@easyCZ
Copy link
Member Author

easyCZ commented Jun 2, 2022

/hold

@easyCZ
Copy link
Member Author

easyCZ commented Jun 2, 2022

/unhold

@roboquat roboquat merged commit f8da3f3 into main Jun 2, 2022
@roboquat roboquat deleted the mp/usage-wsi-model branch June 2, 2022 12:57
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants