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

Reverse index (sk,pk) in addition to (pk,sk) leads to error message #416

Open
mattes3 opened this issue Aug 3, 2024 · 1 comment
Open

Comments

@mattes3
Copy link

mattes3 commented Aug 3, 2024

Describe the bug
I have a reverse GSI on my table, but I fail to make it usable with ElectroDB. Basically, my normal keys are called (pk, sk), but I have a reverse index using (sk, pk). ElectroDB fails with an error message (see below).

ElectroDB Version
2.14.2

ElectroDB Playground Link
This one

Entity/Service Definitions
Include your entity model (or a model that sufficiently recreates your issue) to help troubleshoot.

   attributes: {
      followerID: {
        type: "string",
        required: true
      },
      followingID: {
        type: "string",
        required: true
      },
    },
    indexes: {
      followers: {
        pk: {
          field: "pk",
          composite: ["followingID"]
        },
        sk: {
          field: "sk",
          composite: ["followerID"]
        }
      },
      followings: {
        index: 'GSIreverse',
        pk: {
          field: "sk",
          composite: ["followerID"]
        },
        sk: {
          field: "pk",
          composite: ["followingID"]
        }
      },
    }

Expected behavior
The Entity constructor should run without error.

Errors

This is the error that I get (see the Playground example):

The Sort Key (sk) on Access Pattern 'followings' references the field 'sk' which is already referenced by the Access Pattern(s) 'followers' as a Partition Key. Fields mapped to Partition Keys cannot be also mapped to Sort Keys.

For more detail on this error reference https://electrodb.dev/en/reference/errors/#inconsistent-index-definition

Additional context

I can't believe the error message because having a reverse index is one of the usual tricks in DynamoDB applications. See https://aws.amazon.com/tutorials/design-a-database-for-a-mobile-app-with-dynamodb/module-4/ for an example.

What am I missing here?

@rdzidziguri

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants