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

Robot table #19

Closed
wants to merge 11 commits into from
Closed

Robot table #19

wants to merge 11 commits into from

Conversation

chennisden
Copy link
Contributor

Also set primary key as "id" for all tables and rename "columns" to "keys" ("columns" was quite misleading)

@chennisden
Copy link
Contributor Author

pretend this pr doesnt exist for now i will make a mess of things

@chennisden
Copy link
Contributor Author

This PR is "done" now, but I still wouldn't call the userauth side of db done (not even just what we currently have implemented). The logic with the auth tokens needs to actually ping the db

@chennisden
Copy link
Contributor Author

Im assuming add to waitlit creates a new banned user

chennisden added 10 commits May 30, 2024 11:34
More specifically each "id" key is a String and a primary
key. No secondary keys are admitted.

Note for the future: "columns" is a really bad name for
create_dynamodb_table, maybe keys would be better.
"Columns" is misleading because it implies that every field of the table
ought to be specified, which is contrary to how NoSQL databases work.
but the types are fine because the command runs
this is REALLY IMPORTANT!!!
This will reduce the mental overload when we inevitably need to
deserialzie these tokens!
we want unique ids on everything
@chennisden
Copy link
Contributor Author

rebased on master and force pushed

Copy link
Member

@codekansas codekansas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! small requests

store/app/api/model.py Outdated Show resolved Hide resolved
keys=[
("id", "S", "HASH"),
],
gsis=[("emailIndex", "email", "S", "HASH")],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
gsis=[("emailIndex", "email", "S", "HASH")],
gsis=[
("emailIndex", "email", "S", "HASH"),
],

reason is that if we add more indexes it keeps the file blame easier to parse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially did that, make format is what made it all in one line. I concur, I would have written it in multiple lines, but probably best to obey the linter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you put a comma inside the list, black will format it this way

],
gsis=[("ownerIndex", "owner", "S", "HASH")],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here

@@ -40,16 +43,16 @@ async def add_token(self, token: Token) -> None:

async def get_token(self, email: str) -> Token | None:
table = await self.db.Table("Tokens")
token_dict = await table.get_item(Key={"email": email})
if "Item" not in token_dict:
token_dict = await table.query(IndexName="emailIndex", KeyConditionExpression=Key("email").eq(email))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not get_item here? this should be a unique element right, not a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately DynamoDB does not allow you to get_item on anything besides a primary key. It has no mechanism of enforcing uniqueness on secondary indices, which is why we have to manually check that emails are unique whenever we attempt to perform a user insertion.

Furthermore, even after we manually enforce uniqueness, DynamoDB still has no interest in just returning the first entry with the correct email it finds. There is no method to perform a singular query on a secondary index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind we will only be using email for tokens

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually tokens and the entire auth structure require significant rearch. think it is worth considering using traditional cookie based auth since it is much simpler and easier to implement. (notably i believe this implementation is wrong, though how easy it is to fix is not known to me)

AttributeDefinitions=[{"AttributeName": n, "AttributeType": t} for n, t, _ in columns],
AttributeDefinitions=[
{"AttributeName": n, "AttributeType": t}
for n, t in itertools.chain(((n, t) for (n, t, _) in keys), ((n, t) for _, n, t, _ in gsis))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful :)

store/app/api/crud/base.py Outdated Show resolved Hide resolved
@codekansas
Copy link
Member

closing bc changes got moved onto later branch

@codekansas codekansas closed this May 31, 2024
@codekansas codekansas deleted the robo-table branch May 31, 2024 06:14
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

Successfully merging this pull request may close these issues.

2 participants