Skip to content

[usage] Add db.Project model in golang #10368

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

Merged
merged 2 commits into from
Jun 2, 2022
Merged

Conversation

easyCZ
Copy link
Member

@easyCZ easyCZ commented May 31, 2022

Description

Adds golang model for d_b_project table. Process similar to #10293

Related Issue(s)

How to test

Unit tests

leeway build components/usage:init-testdb

Navigate to the component and do go test ./... to test this and all sub-packages.

Release Notes

NONE

Documentation

NONE

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Many thanks for this PR! Left a few questions in-line for now & will finish this code review later today.

TeamID sql.NullString `gorm:"column:teamId;type:char;size:36;" json:"teamId"`
UserID sql.NullString `gorm:"column:userId;type:char;size:36;" json:"userId"`

MarkedDeleted int32 `gorm:"column:markedDeleted;type:tinyint;default:0;" json:"markedDeleted"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Why use int32 to represent booleans?

  • Shouldn't this be a bool?
  • SQL's tinyint is one byte, so this could also be uint8 or byte

Copy link
Member Author

Choose a reason for hiding this comment

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

The underlying datatype in MySQL is tinyint it looks like, so here it only matches that. I'll see if using a bool results in similar behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated this to bool. It works fine and gives us nicer handling with the model. Great spot!

@easyCZ easyCZ force-pushed the mp/usage-project-model branch from 47991a8 to 5b940b2 Compare June 2, 2022 11:05
@easyCZ easyCZ requested a review from jankeromnes June 2, 2022 11:06
Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Many thanks for adjusting! 👍

A few more comments in-line.

Also, how do you run the unit tests?


SoftDeleted sql.NullString `gorm:"column:softDeleted;type:char;size:4;" json:"softDeleted"`
Pinned int32 `gorm:"column:pinned;type:tinyint;default:0;" json:"pinned"`
Pinned bool `gorm:"column:pinned;type:tinyint;default:0;" json:"pinned"`

// deleted is reserved for use by db-sync
_ int32 `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ int32 `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`
_ bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`

Copy link
Contributor

Choose a reason for hiding this comment

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

Also,

  • Workspace.ID and Workspace.OwnerID could be of type uuid.UUID
  • Workspace.Type could be an enum [1]

Copy link
Member Author

Choose a reason for hiding this comment

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

Good spot. I'd like to leave this part for later PRs once we start using the data from the model and come across this. This will guide us exactly how we want to encapsulated the enum model for this.

@easyCZ
Copy link
Member Author

easyCZ commented Jun 2, 2022

Also, how do you run the unit tests?

Standard go test. Navigate to the component and do go test ./... to test this and all sub-packages.

@jankeromnes
Copy link
Contributor

jankeromnes commented Jun 2, 2022

Standard go test. Navigate to the component and do go test ./... to test this and all sub-packages.

Thanks! I took the liberty to clarify the "How to test" instructions in your PR description. 😇

Also, could these eventually be run by Werft, so that we automatically detect new bugs / regressions? 👀

@jankeromnes
Copy link
Contributor

jankeromnes commented Jun 2, 2022

I tried this -- did I do something wrong?

  1. Open PR in Gitpod
  2. 👇
$ cd components/usage/
$ go test ./...
go: downloading gorm.io/driver/mysql v1.3.3
go: downloading github.com/relvacode/iso8601 v1.1.0
go: downloading gorm.io/gorm v1.23.5
go: downloading github.com/go-sql-driver/mysql v1.6.0
go: downloading gorm.io/datatypes v1.0.6
go: downloading github.com/spf13/cobra v1.4.0
go: downloading github.com/jinzhu/inflection v1.0.0
go: downloading github.com/jinzhu/now v1.1.4
?       github.com/gitpod-io/gitpod/usage       [no test files]
?       github.com/gitpod-io/gitpod/usage/cmd   [no test files]

2022/06/02 11:50:19 /workspace/gitpod/components/usage/pkg/db/conn.go:41
[error] failed to initialize database, got error dial tcp [::1]:23306: connect: connection refused
--- FAIL: TestConnectForTests (0.00s)
    conn_test.go:13: 
                Error Trace:    conn.go:55
                                                        conn_test.go:13
                Error:          Received unexpected error:
                                dial tcp [::1]:23306: connect: connection refused
                Test:           TestConnectForTests
                Messages:       Failed to establish connection to DB. In a workspace, run `leeway build components/usage:init-testdb` once to bootstrap the DB.

2022/06/02 11:50:19 /workspace/gitpod/components/usage/pkg/db/conn.go:41
[error] failed to initialize database, got error dial tcp [::1]:23306: connect: connection refused
--- FAIL: TestProject_ReadExistingRecords (0.00s)
    project_test.go:34: 
                Error Trace:    conn.go:55
                                                        project_test.go:34
                Error:          Received unexpected error:
                                dial tcp [::1]:23306: connect: connection refused
                Test:           TestProject_ReadExistingRecords
                Messages:       Failed to establish connection to DB. In a workspace, run `leeway build components/usage:init-testdb` once to bootstrap the DB.

2022/06/02 11:50:19 /workspace/gitpod/components/usage/pkg/db/conn.go:41
[error] failed to initialize database, got error dial tcp [::1]:23306: connect: connection refused
--- FAIL: TestRead (0.00s)
    workspace_test.go:51: 
                Error Trace:    conn.go:55
                                                        workspace_test.go:51
                Error:          Received unexpected error:
                                dial tcp [::1]:23306: connect: connection refused
                Test:           TestRead
                Messages:       Failed to establish connection to DB. In a workspace, run `leeway build components/usage:init-testdb` once to bootstrap the DB.
FAIL
FAIL    github.com/gitpod-io/gitpod/usage/pkg/db        0.008s
FAIL

@easyCZ
Copy link
Member Author

easyCZ commented Jun 2, 2022

@jankeromnes see instructions in the error message.

Failed to establish connection to DB. In a workspace, run `leeway build components/usage:init-testdb` once to bootstrap the DB.

@easyCZ
Copy link
Member Author

easyCZ commented Jun 2, 2022

Also, could these eventually be run by Werft, so that we automatically detect new bugs / regressions? 👀

The tests are already run by werft :)

See raw logs and search for usage. There are logs from the unit tests.

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Thanks again for helping figure out the test instructions!

All nits are addressed, the code looks good, and it works as advertised. 👍

LGTM* 🐐

*(LGTM = Let Goats Try Minecraft)

@roboquat roboquat merged commit 4c83691 into main Jun 2, 2022
@roboquat roboquat deleted the mp/usage-project-model branch June 2, 2022 12:19
@easyCZ
Copy link
Member Author

easyCZ commented Jun 2, 2022

<3

@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.

3 participants