I was just about to add a separate attribut to every item in the
database named hunt_id when I realized that that was totally redundant
with our existing PK attribute (whose values were simply the hunt_id
prefixed by "hunt-" in all cases).
Since we're not using the PK field in any generalized sense, (that is,
it's _always_ populated with the hunt_id value), it's much simpler and
more efficient to just name it "hunt_id" and store the hunt_id valeu
ther directly (without any prefix).
response = turb.table.query(
KeyConditionExpression=(
response = turb.table.query(
KeyConditionExpression=(
- Key('PK').eq('hunt-{}'.format(hunt_id)) &
+ Key('hunt_id').eq(hunt_id) &
Key('SK').begins_with('puzzle-')
)
)
Key('SK').begins_with('puzzle-')
)
)
turb.table = turb.db.create_table(
TableName='turbot',
KeySchema=[
turb.table = turb.db.create_table(
TableName='turbot',
KeySchema=[
- {'AttributeName': 'PK', 'KeyType': 'HASH'},
+ {'AttributeName': 'hunt_id', 'KeyType': 'HASH'},
{'AttributeName': 'SK', 'KeyType': 'RANGE'},
],
AttributeDefinitions=[
{'AttributeName': 'SK', 'KeyType': 'RANGE'},
],
AttributeDefinitions=[
- {'AttributeName': 'PK', 'AttributeType': 'S'},
+ {'AttributeName': 'hunt_id', 'AttributeType': 'S'},
{'AttributeName': 'SK', 'AttributeType': 'S'},
{'AttributeName': 'channel_id', 'AttributeType': 'S'},
{'AttributeName': 'is_hunt', 'AttributeType': 'S'},
{'AttributeName': 'SK', 'AttributeType': 'S'},
{'AttributeName': 'channel_id', 'AttributeType': 'S'},
{'AttributeName': 'is_hunt', 'AttributeType': 'S'},
# (leaving it as non-active for now until the channel-created handler
# finishes fixing it up with a sheet and a companion table)
item={
# (leaving it as non-active for now until the channel-created handler
# finishes fixing it up with a sheet and a companion table)
item={
- "PK": "hunt-{}".format(hunt_id),
"SK": "hunt-{}".format(hunt_id),
"is_hunt": hunt_id,
"SK": "hunt-{}".format(hunt_id),
"is_hunt": hunt_id,
"channel_id": channel_id,
"active": False,
"name": name,
"channel_id": channel_id,
"active": False,
"name": name,
"""
turbot_table = turb.db.Table("turbot")
"""
turbot_table = turb.db.Table("turbot")
- response = turbot_table.get_item(Key={'PK': 'hunt-{}'.format(hunt_id)})
+ response = turbot_table.get_item(Key={'hunt_id': hunt_id})
if 'Item' in response:
return response['Item']
if 'Item' in response:
return response['Item']
# Insert the newly-created puzzle into the database
item={
# Insert the newly-created puzzle into the database
item={
- "PK": "hunt-{}".format(hunt_id),
"SK": "puzzle-{}".format(puzzle_id),
"puzzle_id": puzzle_id,
"channel_id": channel_id,
"SK": "puzzle-{}".format(puzzle_id),
"puzzle_id": puzzle_id,
"channel_id": channel_id,