-
Notifications
You must be signed in to change notification settings - Fork 89
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
Enhancement: update indexer table schema #1143
Changes from 3 commits
fd679ca
823dea4
aea3dde
434c0a5
6cf27ca
16d2c0e
6c1b28f
86734eb
67bba79
8777f9d
b41a349
faa6b77
e15fe45
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 |
---|---|---|
|
@@ -24,11 +24,44 @@ func TestConvertAccountDataIncrementsMigrationNumber(t *testing.T) { | |
err := db.setMigrationState(nil, &migrationState) | ||
require.NoError(t, err) | ||
|
||
err = convertAccountData(&db, &migrationState, nil) | ||
err = convertAccountData(&db, &migrationState) | ||
require.NoError(t, err) | ||
|
||
migrationState, err = db.getMigrationState(context.Background(), nil) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, types.MigrationState{NextMigration: 6}, migrationState) | ||
} | ||
|
||
func TestConvertBigIntType(t *testing.T) { | ||
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. Not sure if this is necessary, but should we add a test case that asserts the existing values aren't changed by the type conversion? i.e. insert round 1,000,000 convert the type and assert that the round is still 1,000,000? 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. I think this can be covered by running the block validator. |
||
pdb, _, shutdownFunc := pgtest.SetupPostgresWithSchema(t) | ||
defer shutdownFunc() | ||
|
||
db := IndexerDb{db: pdb} | ||
defer db.Close() | ||
|
||
// old table schema. insert a record with round 18446744073709551613 | ||
query := "INSERT INTO txn_participation(addr,round,intra) VALUES('\\x013d7d16d7ad4fefb61bd95b765c8ceb'::bytea,18446744073709551613,1)" | ||
_, err := pdb.Exec(context.Background(), query) | ||
assert.Contains(t, err.Error(), "ERROR: bigint out of range") | ||
|
||
// run type conversion | ||
migrationState := types.MigrationState{ | ||
NextMigration: 6, | ||
} | ||
err = db.setMigrationState(nil, &migrationState) | ||
require.NoError(t, err) | ||
|
||
err = convertBigIntType(&db, &migrationState) | ||
require.NoError(t, err) | ||
|
||
migrationState, err = db.getMigrationState(context.Background(), nil) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, types.MigrationState{NextMigration: 7}, migrationState) | ||
|
||
// after table schema is updated. insert a record with round 18446744073709551613 | ||
_, err = pdb.Exec(context.Background(), query) | ||
assert.NoError(t, err) | ||
|
||
} |
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.
What is the rationale behind choosing 20 as opposed to another number?
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.
this is because uint64 max is 18446744073709551615 and it's a value of 20 digits.
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.
Got it thanks!