Skip to content

Use constants for storage table names in repo tests#74

Merged
rmulhol merged 3 commits intostagingfrom
use-table-constants
Dec 19, 2019
Merged

Use constants for storage table names in repo tests#74
rmulhol merged 3 commits intostagingfrom
use-table-constants

Conversation

@elizabethengelman
Copy link
Copy Markdown
Contributor

No description provided.

Metadata: storage.GetValueMetadata(cat.IlkLump, map[storage.Key]string{constants.Ilk: test_helpers.FakeIlk.Hex}, storage.Uint256),
PropertyName: "Lump",
PropertyValue: strconv.Itoa(rand.Int()),
TableName: "maker.cat_ilk_lump",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was thinking of making a similar change in some of the other places we're hardcoding table names, but I'm not sure if that would reduce the readability of queries... ie. line 204

err = db.Get(&result, `SELECT diff_id, header_id, ilk_id AS key, lump AS value FROM maker.cat_ilk_lump`)

could become

err = db.Get(&result, `SELECT diff_id, header_id, ilk_id AS key, lump AS value FROM $1`,
     shared.GetFullTableName(constants.MakerSchema, constants.CatIlkLump)
)

What do you all think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 I don't think it impacts the readability that much. After FROM my brain just thinks "..what table is this coming FROM?"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a fan of the change - to me the readability concern is outweighed by the scope of change entailed by updating a table name 👍

schema := "schema_name"
table := "table_name"
fullTableName := shared.GetFullTableName(schema, table)
Expect(fullTableName).To(Equal("schema_name.table_name"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⭐️

Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

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

Awesome!


// storage tables
const (
CdpManagerVat = "cdp_manager_vat"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be a fan of adding Table to the end of these names so it's clear what purpose they serve when imported in other packages, though not sure whether that could cause collisions with the event tables?

import (
"database/sql"
"fmt"
"github.com/makerdao/vdb-mcd-transformers/transformers/shared"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👀

@elizabethengelman elizabethengelman force-pushed the use-table-constants branch 2 times, most recently from 3f1c398 to a088fa2 Compare December 19, 2019 19:52
@rmulhol rmulhol merged commit 14ec39c into staging Dec 19, 2019
@rmulhol rmulhol deleted the use-table-constants branch December 19, 2019 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants