aws / aws/aws-record-ruby

If you forget to create a schema, weird error messages ensue

Open
#54 8 comments 0 reactions 0 assignees View on GitHub
feature-request
Dominant language
Ruby
Stars
318
Forks
43
Avg merge
19h
Merged PRs (30d)
1

Description

I am a stupid idiot, and I forgot to add `hash_key: true` to the actual, uh, `hash_key`. This is a dumb thing that dumb people do and I lost hours from it due to my own stupidity.

However, the library never told me "Hey, idiot, I don't know how to handle your aws-record object because you never told me what your actual keys were." That would've been nice :(

I suspect, also, that you can probably inadvertently specify **two** `hash_key`'s, and the library won't care.

Ideally, when the Class is first created might be the best time to check for this, but I think you might not ever get a signal that 'oh, yeah, the user is finished defining their class'.

So instead, maybe we could put something in the `save()` method that, when it's walking through the keys to see if any of them have changed (to see if this is a 'new record' or an 'update'), we can use the following algorithm:

1) Check to see if a temporary variable (that was initialized to `false`) is true, if so skip this check. Something like `schema_checked?`
2) Otherwise, we look for exactly-only-one hash key, and optionally, perhaps only-one range key. More than one range key or not exactly one hash key should throw an exception, something like `Aws::Record::SchemaNotSpecified` or `Aws::Record::SchemaInvalid`, ideally with some helpful further information like "No Hash Key defined" or "More than one Hash Key defined" or "More than one Range Key Defined".
3) Set `schema_checked?` to `true`, so this code doesn't get run again.

Perhaps that optimization isn't necessary, but lots of people who use DynamoDB use it for performance reasons, and so if they're really beating up on the DB, then repeatedly walking through the defined schema seems wasteful.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.