Skip to content

Commit

Permalink
Code review tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalouf committed Apr 30, 2024
1 parent 6bb6442 commit 963027d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions ledger/store/trackerdb/sqlitedriver/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,12 @@ func accountsAddCreatableTypeColumn(ctx context.Context, e db.Executable, popula
// Run ctype resources migration if it hasn't run yet
var creatableTypeOnResourcesRun bool
err := e.QueryRow("SELECT 1 FROM pragma_table_info('resources') WHERE name='ctype'").Scan(&creatableTypeOnResourcesRun)
if !errors.Is(err, sql.ErrNoRows) {
if err == nil {
// Already exists.
return nil

Check warning on line 952 in ledger/store/trackerdb/sqlitedriver/schema.go

View check run for this annotation

Codecov / codecov/patch

ledger/store/trackerdb/sqlitedriver/schema.go#L952

Added line #L952 was not covered by tests
}
} else if !errors.Is(err, sql.ErrNoRows) {
return err

Check warning on line 954 in ledger/store/trackerdb/sqlitedriver/schema.go

View check run for this annotation

Codecov / codecov/patch

ledger/store/trackerdb/sqlitedriver/schema.go#L954

Added line #L954 was not covered by tests
} // A sql.ErrNoRows error means the column does not exist, so we need to create it

// Add ctype column
createStmt := `ALTER TABLE resources ADD COLUMN ctype INTEGER NOT NULL DEFAULT -1`
Expand Down
8 changes: 6 additions & 2 deletions ledger/store/trackerdb/testsuite/accounts_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ func CustomTestResourcesQueryAllLimited(t *customT) {
resDataA1AcctA := trackerdb.ResourcesData{}
appParams := ledgertesting.RandomAppParams()
resDataA1AcctA.SetAppParams(appParams, true)
resDataA1AcctA.SetAppLocalState(basics.AppLocalState{})
resDataA1AcctB := trackerdb.ResourcesData{}
appParamsB := ledgertesting.RandomAppParams()
resDataA1AcctB.SetAppParams(appParamsB, true)
resDataA1AcctB.SetAppLocalState(basics.AppLocalState{})
aidxResA1 := basics.CreatableIndex(2)
_, err = aow.InsertResource(refAccA, aidxResA1, resDataA1AcctA)
require.NoError(t, err)
Expand Down Expand Up @@ -383,6 +383,10 @@ func CustomTestResourcesQueryAllLimited(t *customT) {
require.Equal(t, resDataWithParamsA0AcctB, prs[0].Data)
require.Equal(t, expectedRound, rnd) // db round (from the return)

// Delete app owner for A-1
_, err = aow.DeleteCreatable(aidxResA1, basics.AppCreatable)
require.NoError(t, err)

// Set min to 1, should return only 1 resource (index 1)
prs, rnd, err = aor.LookupLimitedResources(addrB, 1, 1, basics.AssetCreatable)
require.NoError(t, err)
Expand Down

0 comments on commit 963027d

Please sign in to comment.