fix(eventstore): revert precise decimal (#8527) (#8679)

This commit is contained in:
Tim Möhlmann
2024-09-24 19:43:29 +03:00
committed by GitHub
parent eb97be6fdf
commit aeb379e7de
47 changed files with 215 additions and 319 deletions

View File

@@ -8,8 +8,6 @@ import (
"testing"
"time"
"github.com/shopspring/decimal"
"github.com/zitadel/zitadel/internal/v2/database/mock"
"github.com/zitadel/zitadel/internal/v2/eventstore"
"github.com/zitadel/zitadel/internal/zerrors"
@@ -820,7 +818,7 @@ func Test_push(t *testing.T) {
[][]driver.Value{
{
time.Now(),
decimal.NewFromFloat(123).String(),
float64(123),
},
},
),
@@ -901,11 +899,11 @@ func Test_push(t *testing.T) {
[][]driver.Value{
{
time.Now(),
decimal.NewFromFloat(123).String(),
float64(123),
},
{
time.Now(),
decimal.NewFromFloat(123.1).String(),
float64(123.1),
},
},
),
@@ -986,11 +984,11 @@ func Test_push(t *testing.T) {
[][]driver.Value{
{
time.Now(),
decimal.NewFromFloat(123).String(),
float64(123),
},
{
time.Now(),
decimal.NewFromFloat(123.1).String(),
float64(123.1),
},
},
),
@@ -1046,7 +1044,7 @@ func Test_push(t *testing.T) {
[][]driver.Value{
{
time.Now(),
decimal.NewFromFloat(123).String(),
float64(123),
},
},
),
@@ -1101,7 +1099,7 @@ func Test_push(t *testing.T) {
[][]driver.Value{
{
time.Now(),
decimal.NewFromFloat(123).String(),
float64(123),
},
},
),
@@ -1183,11 +1181,11 @@ func Test_push(t *testing.T) {
[][]driver.Value{
{
time.Now(),
decimal.NewFromFloat(123).String(),
float64(123),
},
{
time.Now(),
decimal.NewFromFloat(123.1).String(),
float64(123.1),
},
},
),
@@ -1274,11 +1272,11 @@ func Test_push(t *testing.T) {
[][]driver.Value{
{
time.Now(),
decimal.NewFromFloat(123).String(),
float64(123),
},
{
time.Now(),
decimal.NewFromFloat(123.1).String(),
float64(123.1),
},
},
),

View File

@@ -8,8 +8,6 @@ import (
"testing"
"time"
"github.com/shopspring/decimal"
"github.com/zitadel/zitadel/internal/v2/database"
"github.com/zitadel/zitadel/internal/v2/database/mock"
"github.com/zitadel/zitadel/internal/v2/eventstore"
@@ -543,13 +541,13 @@ func Test_writeFilter(t *testing.T) {
args: args{
filter: eventstore.NewFilter(
eventstore.FilterPagination(
eventstore.PositionGreater(decimal.NewFromFloat(123.4), 0),
eventstore.PositionGreater(123.4, 0),
),
),
},
want: wantQuery{
query: " WHERE instance_id = $1 AND position > $2 ORDER BY position, in_tx_order",
args: []any{"i1", decimal.NewFromFloat(123.4)},
args: []any{"i1", 123.4},
},
},
{
@@ -557,18 +555,18 @@ func Test_writeFilter(t *testing.T) {
args: args{
filter: eventstore.NewFilter(
eventstore.FilterPagination(
// eventstore.PositionGreater(decimal.NewFromFloat(123.4), 0),
// eventstore.PositionGreater(123.4, 0),
// eventstore.PositionLess(125.4, 10),
eventstore.PositionBetween(
&eventstore.GlobalPosition{Position: decimal.NewFromFloat(123.4)},
&eventstore.GlobalPosition{Position: decimal.NewFromFloat(125.4), InPositionOrder: 10},
&eventstore.GlobalPosition{Position: 123.4},
&eventstore.GlobalPosition{Position: 125.4, InPositionOrder: 10},
),
),
),
},
want: wantQuery{
query: " WHERE instance_id = $1 AND ((position = $2 AND in_tx_order < $3) OR position < $4) AND position > $5 ORDER BY position, in_tx_order",
args: []any{"i1", decimal.NewFromFloat(125.4), uint32(10), decimal.NewFromFloat(125.4), decimal.NewFromFloat(123.4)},
args: []any{"i1", 125.4, uint32(10), 125.4, 123.4},
// TODO: (adlerhurst) would require some refactoring to reuse existing args
// query: " WHERE instance_id = $1 AND position > $2 AND ((position = $3 AND in_tx_order < $4) OR position < $3) ORDER BY position, in_tx_order",
// args: []any{"i1", 123.4, 125.4, uint32(10)},
@@ -579,13 +577,13 @@ func Test_writeFilter(t *testing.T) {
args: args{
filter: eventstore.NewFilter(
eventstore.FilterPagination(
eventstore.PositionGreater(decimal.NewFromFloat(123.4), 12),
eventstore.PositionGreater(123.4, 12),
),
),
},
want: wantQuery{
query: " WHERE instance_id = $1 AND ((position = $2 AND in_tx_order > $3) OR position > $4) ORDER BY position, in_tx_order",
args: []any{"i1", decimal.NewFromFloat(123.4), uint32(12), decimal.NewFromFloat(123.4)},
args: []any{"i1", 123.4, uint32(12), 123.4},
},
},
{
@@ -595,13 +593,13 @@ func Test_writeFilter(t *testing.T) {
eventstore.FilterPagination(
eventstore.Limit(10),
eventstore.Offset(3),
eventstore.PositionGreater(decimal.NewFromFloat(123.4), 12),
eventstore.PositionGreater(123.4, 12),
),
),
},
want: wantQuery{
query: " WHERE instance_id = $1 AND ((position = $2 AND in_tx_order > $3) OR position > $4) ORDER BY position, in_tx_order LIMIT $5 OFFSET $6",
args: []any{"i1", decimal.NewFromFloat(123.4), uint32(12), decimal.NewFromFloat(123.4), uint32(10), uint32(3)},
args: []any{"i1", 123.4, uint32(12), 123.4, uint32(10), uint32(3)},
},
},
{
@@ -611,14 +609,14 @@ func Test_writeFilter(t *testing.T) {
eventstore.FilterPagination(
eventstore.Limit(10),
eventstore.Offset(3),
eventstore.PositionGreater(decimal.NewFromFloat(123.4), 12),
eventstore.PositionGreater(123.4, 12),
),
eventstore.AppendAggregateFilter("user"),
),
},
want: wantQuery{
query: " WHERE instance_id = $1 AND aggregate_type = $2 AND ((position = $3 AND in_tx_order > $4) OR position > $5) ORDER BY position, in_tx_order LIMIT $6 OFFSET $7",
args: []any{"i1", "user", decimal.NewFromFloat(123.4), uint32(12), decimal.NewFromFloat(123.4), uint32(10), uint32(3)},
args: []any{"i1", "user", 123.4, uint32(12), 123.4, uint32(10), uint32(3)},
},
},
{
@@ -628,7 +626,7 @@ func Test_writeFilter(t *testing.T) {
eventstore.FilterPagination(
eventstore.Limit(10),
eventstore.Offset(3),
eventstore.PositionGreater(decimal.NewFromFloat(123.4), 12),
eventstore.PositionGreater(123.4, 12),
),
eventstore.AppendAggregateFilter("user"),
eventstore.AppendAggregateFilter(
@@ -639,7 +637,7 @@ func Test_writeFilter(t *testing.T) {
},
want: wantQuery{
query: " WHERE instance_id = $1 AND (aggregate_type = $2 OR (aggregate_type = $3 AND aggregate_id = $4)) AND ((position = $5 AND in_tx_order > $6) OR position > $7) ORDER BY position, in_tx_order LIMIT $8 OFFSET $9",
args: []any{"i1", "user", "org", "o1", decimal.NewFromFloat(123.4), uint32(12), decimal.NewFromFloat(123.4), uint32(10), uint32(3)},
args: []any{"i1", "user", "org", "o1", 123.4, uint32(12), 123.4, uint32(10), uint32(3)},
},
},
}
@@ -958,7 +956,7 @@ func Test_writeQueryUse_examples(t *testing.T) {
),
eventstore.FilterPagination(
// used because we need to check for first login and an app which is not console
eventstore.PositionGreater(decimal.NewFromInt(12), 4),
eventstore.PositionGreater(12, 4),
),
),
eventstore.NewFilter(
@@ -1067,9 +1065,9 @@ func Test_writeQueryUse_examples(t *testing.T) {
"instance",
"user",
"user.token.added",
decimal.NewFromInt(12),
float64(12),
uint32(4),
decimal.NewFromInt(12),
float64(12),
"instance",
"instance",
[]string{"instance.idp.config.added", "instance.idp.oauth.added", "instance.idp.oidc.added", "instance.idp.jwt.added", "instance.idp.azure.added", "instance.idp.github.added", "instance.idp.github.enterprise.added", "instance.idp.gitlab.added", "instance.idp.gitlab.selfhosted.added", "instance.idp.google.added", "instance.idp.ldap.added", "instance.idp.config.apple.added", "instance.idp.saml.added"},
@@ -1203,7 +1201,7 @@ func Test_executeQuery(t *testing.T) {
time.Now(),
"event.type",
uint32(23),
decimal.NewFromInt(123).String(),
float64(123),
uint32(0),
nil,
"gigi",
@@ -1237,7 +1235,7 @@ func Test_executeQuery(t *testing.T) {
time.Now(),
"event.type",
uint32(23),
decimal.NewFromInt(123).String(),
float64(123),
uint32(0),
[]byte(`{"name": "gigi"}`),
"gigi",
@@ -1271,7 +1269,7 @@ func Test_executeQuery(t *testing.T) {
time.Now(),
"event.type",
uint32(23),
decimal.NewFromInt(123).String(),
float64(123),
uint32(0),
nil,
"gigi",
@@ -1285,7 +1283,7 @@ func Test_executeQuery(t *testing.T) {
time.Now(),
"event.type",
uint32(24),
decimal.NewFromInt(124).String(),
float64(124),
uint32(0),
[]byte(`{"name": "gigi"}`),
"gigi",
@@ -1319,7 +1317,7 @@ func Test_executeQuery(t *testing.T) {
time.Now(),
"event.type",
uint32(23),
decimal.NewFromInt(123).String(),
float64(123),
uint32(0),
nil,
"gigi",
@@ -1333,7 +1331,7 @@ func Test_executeQuery(t *testing.T) {
time.Now(),
"event.type",
uint32(24),
decimal.NewFromInt(124).String(),
float64(124),
uint32(0),
[]byte(`{"name": "gigi"}`),
"gigi",