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

Fix index creation on nested fields #2637

Merged
merged 11 commits into from
May 19, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
change to expectedDefinition
  • Loading branch information
wqhhust committed May 17, 2023
commit e23de450835c7f9b3ca34073a9c08812b3417ef8
13 changes: 6 additions & 7 deletions internal/handlers/pg/pgdb/indexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestCreateIndexIfNotExists(t *testing.T) {
setupDatabase(ctx, t, pool, databaseName)

for name, tc := range map[string]struct {
expecteDefinition string // the expected index definition in postgresql
index Index // the index to create
expectedDefinition string // the expected index definition in postgresql
index Index // the index to create
}{
"keyWithoutNestedField": {
index: Index{
Expand All @@ -51,7 +51,7 @@ func TestCreateIndexIfNotExists(t *testing.T) {
{Field: "bar", Order: types.Descending},
},
},
expecteDefinition: "((_jsonb -> 'foo'::text)), ((_jsonb -> 'bar'::text)) DESC",
expectedDefinition: "((_jsonb -> 'foo'::text)), ((_jsonb -> 'bar'::text)) DESC",
},
"keyWithNestedField_level1": {
index: Index{
Expand All @@ -60,7 +60,7 @@ func TestCreateIndexIfNotExists(t *testing.T) {
{Field: "foo.bar", Order: types.Ascending},
},
},
expecteDefinition: "(((_jsonb -> 'foo'::text) -> 'bar'::text))",
expectedDefinition: "(((_jsonb -> 'foo'::text) -> 'bar'::text))",
},
"keyWithNestedField_level2": {
index: Index{
Expand All @@ -69,10 +69,9 @@ func TestCreateIndexIfNotExists(t *testing.T) {
{Field: "foo.bar.c", Order: types.Ascending},
},
},
expecteDefinition: "((((_jsonb -> 'foo'::text) -> 'bar'::text) -> 'c'::text))",
expectedDefinition: "((((_jsonb -> 'foo'::text) -> 'bar'::text) -> 'c'::text))",
},
} {
// https://gist.github.com/posener/92a55c4cd441fc5e5e85f27bca008721#how-to-solve-this
tc := tc

t.Run(name, func(t *testing.T) {
Expand All @@ -97,7 +96,7 @@ func TestCreateIndexIfNotExists(t *testing.T) {

expectedIndexdef := fmt.Sprintf(
"CREATE INDEX %s ON \"%s\".%s USING btree (%s)",
pgIndexName, databaseName, tableName, tc.expecteDefinition,
pgIndexName, databaseName, tableName, tc.expectedDefinition,
)
assert.Equal(t, expectedIndexdef, indexdef)
})
Expand Down