-
Notifications
You must be signed in to change notification settings - Fork 502
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
Fix sum of asset in circulation in all assets endpoint #436
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,16 +48,16 @@ func (q *Q) BalancesForAsset( | |
assetType int32, | ||
assetCode string, | ||
assetIssuer string, | ||
) (int32, int64, error) { | ||
) (int32, string, error) { | ||
sql := selectBalances.Where(sq.Eq{ | ||
"assettype": assetType, | ||
"assetcode": assetCode, | ||
"issuer": assetIssuer, | ||
"flags": 1, | ||
}) | ||
result := struct { | ||
Count int32 `db:"count"` | ||
Sum int64 `db:"sum"` | ||
Count int32 `db:"count"` | ||
Sum string `db:"sum"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the query below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point which also shows we need a test for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, it seems we're good here because postgres returns |
||
}{} | ||
err := q.Get(&result, sql) | ||
return result.Count, result.Sum, err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,7 +128,7 @@ type Asset struct { | |
// AssetStat is a row in the asset_stats table representing the stats per Asset | ||
type AssetStat struct { | ||
ID int64 `db:"id"` | ||
Amount int64 `db:"amount"` | ||
Amount string `db:"amount"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will need the db upgrade script like we discussed on slack -- change the row in the assetStats table to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
NumAccounts int32 `db:"num_accounts"` | ||
Flags int8 `db:"flags"` | ||
Toml string `db:"toml"` | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ SET default_with_oids = false; | |
|
||
CREATE TABLE asset_stats ( | ||
id bigint NOT NULL, | ||
amount bigint NOT NULL, | ||
amount character varying NOT NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this supposed to be left as-is?? @bartekn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK, latest.sql should contain the schema dump after applying all migrations. From @nullstyle:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok good to know. so I guess there's some logic which knows when to apply latest vs migrations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nikhilsaraf There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, just for my curiosity.. do we also then run migrations after that and how would it interact in a case where the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
num_accounts integer NOT NULL, | ||
flags smallint NOT NULL, | ||
toml character varying(64) NOT NULL | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- +migrate Up | ||
ALTER TABLE asset_stats | ||
ALTER COLUMN amount SET DATA TYPE character varying; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need a "using" like below? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tested it, it was only required for
No, |
||
|
||
-- +migrate Down | ||
ALTER TABLE asset_stats | ||
ALTER COLUMN amount SET DATA TYPE bigint USING amount::bigint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bartekn should this be
1009876000 * 10^7
="10098760000000000"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's converted in
resources.AssetStat.Populate
.