Skip to content
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

[Merged by Bors] - Don't set atx version in migration 18 #6011

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sql/atxs/atxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ func getBlob(ctx context.Context, db sql.Executor, id []byte, blob *sql.Blob) (t
return 0, fmt.Errorf("%w: atx %s", sql.ErrNotFound, types.BytesToATXID(id))
}

// The migration adding the version column does not set it to 1 for existing ATXs.
// Thus, both values 0 and 1 mean V1.
if version == 0 {
version = types.AtxV1
}
poszu marked this conversation as resolved.
Show resolved Hide resolved
return version, nil
}

Expand Down
18 changes: 18 additions & 0 deletions sql/atxs/atxs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,24 @@ func TestLoadBlob(t *testing.T) {
require.Equal(t, []int{len(blob1.Bytes), -1, len(blob2.Bytes)}, blobSizes)
}

func TestLoadBlob_DefaultsToV1(t *testing.T) {
db := sql.InMemory()

sig, err := signing.NewEdSigner()
require.NoError(t, err)
atx := newAtx(t, sig)
atx.AtxBlob.Blob = []byte("blob1")
atx.AtxBlob.Version = 0

require.NoError(t, atxs.Add(db, atx))

var blob sql.Blob
version, err := atxs.LoadBlob(context.Background(), db, atx.ID().Bytes(), &blob)
require.NoError(t, err)
require.Equal(t, types.AtxV1, version)
require.Equal(t, atx.AtxBlob.Blob, blob.Bytes)
}

func TestGetBlobCached(t *testing.T) {
db := sql.InMemory(sql.WithQueryCache(true))
ctx := context.Background()
Expand Down
1 change: 0 additions & 1 deletion sql/migrations/state/0018_atx_blob_version.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-- Add version column to make it easier to decode the blob
-- to the right version of ATX.
ALTER TABLE atx_blobs ADD COLUMN version INTEGER;
UPDATE atx_blobs SET version = 1;
Loading