Skip to content

[cost center] put all costcenter access behind API #12776

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 1 commit into from
Sep 9, 2022

Conversation

svenefftinge
Copy link
Member

@svenefftinge svenefftinge commented Sep 8, 2022

Description

This change has unfortunately gotten a little big (still practicing keeping things small 😇).
It does the following:

  • introduce a write API for cost center on the usagecomponent
  • replace any direct DB access of cost center in server with this API
  • added creationTime and billingStrategy to cost center

Related Issue(s)

Fixes #

How to test

You can verify that everything still works by joining the Gitpod team and changing the spending limit

Release Notes

NONE

Documentation

Werft options:

  • /werft with-preview
  • /werft with-payment

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-sefftinge-ubp-model-free-plan-and-12741.3 because the annotations in the pull request description changed
(with .werft/ from main)

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-sefftinge-ubp-model-free-plan-and-12741.4 because the annotations in the pull request description changed
(with .werft/ from main)

@svenefftinge svenefftinge force-pushed the sefftinge/ubp-model-free-plan-and-12741 branch from 81c2b3f to 084ddba Compare September 9, 2022 07:36
@svenefftinge svenefftinge marked this pull request as ready for review September 9, 2022 07:52
@svenefftinge svenefftinge requested a review from a team September 9, 2022 07:52
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Sep 9, 2022
@andrew-farries
Copy link
Contributor

/hold

@andrew-farries
Copy link
Contributor

Added the hold for question about the data type.

@andrew-farries
Copy link
Contributor

/unhold

@roboquat roboquat merged commit 74bc751 into main Sep 9, 2022
@roboquat roboquat deleted the sefftinge/ubp-model-free-plan-and-12741 branch September 9, 2022 09:25

// deleted is restricted for use by db-sync
_ bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`
LastModified time.Time `gorm:"->:column:_lastModified;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"_lastModified"`
Copy link
Member

Choose a reason for hiding this comment

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

out of curiosity: are the gorm definitions manually crafted, or is there a tool to sync them?

Copy link
Member Author

Choose a reason for hiding this comment

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

manual

Copy link
Member

Choose a reason for hiding this comment

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

There's a tool which can generate them from the DB schema. I used those initially to set up the definitions but often requires some manual tweaking.

Copy link
Member Author

Choose a reason for hiding this comment

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

Something I actually forgot to mention in yesterday's retro is that I'm getting a little tired of maintaining/writing all the different technical representations (DB & protobuf for TS&Go) of the same shapes. Feels like a lot of code (e.g. this PR) is really just about shoveling data through the stack by copying it into different formats. 😓

Copy link
Member

Choose a reason for hiding this comment

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

That's fair. Codegen can help but it's also important to keep the API shape independent of the shape of the DB. It tends to start very similar, but over time changes. The DB is expected to evolve while the API is expected to retain compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think it would already help if we didn't need to duplicate API to route dashboard requests through server. Also, I think the manual sugar.ts code could maybe be generated.

public async up(queryRunner: QueryRunner): Promise<void> {
if (!(await columnExists(queryRunner, D_B_COST_CENTER, COL_CREATION_TIME))) {
await queryRunner.query(
`ALTER TABLE ${D_B_COST_CENTER} ADD COLUMN ${COL_CREATION_TIME} varchar(30) NOT NULL, ALGORITHM=INPLACE, LOCK=NONE `,
Copy link
Member

Choose a reason for hiding this comment

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

they will be filled up with the implicit default value for the varchar type right? which is '', an empty string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, true. That was not my intend, but I think it will not break.

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'm actually not sure what MYSQL will do with existing records here 😬 The migration worked well against an empty table.

Copy link
Member Author

@svenefftinge svenefftinge Sep 9, 2022

Choose a reason for hiding this comment

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

they will be filled up with the implicit default value for the varchar type right? which is '', an empty string.

Just verified that this is the case indeed

@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Sep 13, 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/XXL team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants