Skip to content

Commit

Permalink
Functions: fixing S4 ORM (smartcontractkit#10596)
Browse files Browse the repository at this point in the history
* Functions: fixing S4 ORM

* Functions: fixing S4 ORM

* Fixed test
  • Loading branch information
Andrei Smirnov authored Sep 12, 2023
1 parent 3ac616a commit 079f749
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/services/s4/postgres_orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ RETURNING id;`, o.tableName)
if errors.Is(err, sql.ErrNoRows) {
return ErrVersionTooLow
}
return nil
return err
}

func (o orm) DeleteExpired(limit uint, utcNow time.Time, qopts ...pg.QOpt) (int64, error) {
Expand Down
20 changes: 20 additions & 0 deletions core/services/s4/postgres_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package s4_test

import (
"errors"
"math"
"testing"
"time"

Expand Down Expand Up @@ -257,3 +258,22 @@ func TestPostgresORM_Namespace(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, snapshotA, n)
}

func TestPostgresORM_BigIntVersion(t *testing.T) {
t.Parallel()

orm := setupORM(t, "test")
row := generateTestRows(t, 1)[0]
row.Version = math.MaxUint64 - 10

err := orm.Update(row)
assert.NoError(t, err)

row.Version++
err = orm.Update(row)
assert.NoError(t, err)

gotRow, err := orm.Get(row.Address, row.SlotId)
assert.NoError(t, err)
assert.Equal(t, row, gotRow)
}
7 changes: 7 additions & 0 deletions core/store/migrate/migrations/0193_s4_alter_version_type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- +goose Up

ALTER TABLE "s4".shared ALTER COLUMN version TYPE NUMERIC;

-- +goose Down

ALTER TABLE "s4".shared ALTER COLUMN version TYPE INT USING version::integer;

0 comments on commit 079f749

Please sign in to comment.