From 963027d6913a0d1fceaf04c828127e061c91982c Mon Sep 17 00:00:00 2001 From: Gary Malouf <982483+gmalouf@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:39:28 -0400 Subject: [PATCH] Code review tweaks. --- ledger/store/trackerdb/sqlitedriver/schema.go | 7 +++++-- ledger/store/trackerdb/testsuite/accounts_kv_test.go | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ledger/store/trackerdb/sqlitedriver/schema.go b/ledger/store/trackerdb/sqlitedriver/schema.go index 71154cd98b..eb17d1fbd7 100644 --- a/ledger/store/trackerdb/sqlitedriver/schema.go +++ b/ledger/store/trackerdb/sqlitedriver/schema.go @@ -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 - } + } else if !errors.Is(err, sql.ErrNoRows) { + return err + } // 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` diff --git a/ledger/store/trackerdb/testsuite/accounts_kv_test.go b/ledger/store/trackerdb/testsuite/accounts_kv_test.go index fa5658c871..b804ec8cb9 100644 --- a/ledger/store/trackerdb/testsuite/accounts_kv_test.go +++ b/ledger/store/trackerdb/testsuite/accounts_kv_test.go @@ -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) @@ -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)