Skip to content

Commit

Permalink
[WIP] Adding code to generate v2 reports
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamps committed Jul 31, 2024
1 parent f1bcc5c commit 04b7a0e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
15 changes: 7 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'
version: "3.8"
services:
dynamodb-local:
# command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data"
Expand All @@ -12,16 +12,17 @@ services:
restart: unless-stopped
command: -jar DynamoDBLocal.jar -sharedDb -dbPath /opt/dynamodblocal
volumes:
- dynamodb_data:/opt/dynamodblocal
- dynamodb_data:/opt/dynamodblocal
ports:
- "8000:8000"
- "8000:8000"
user: root
admin:
env_file: .env.local
build:
context: .
dockerfile: ddbadmin.Dockerfile
ports:
- 8001:8001
- 8001:8001
environment:
- DYNAMO_ENDPOINT=http://dynamodb-local:8000
- AWS_REGION=ap-south-1
Expand All @@ -30,6 +31,7 @@ services:
depends_on:
- dynamodb-local
app:
env_file: .env.local
build: .
volumes:
- "./app:/code"
Expand All @@ -38,10 +40,7 @@ services:
depends_on:
- dynamodb-local
environment:
- DYNAMODB_URL=http://dynamodb-local:8000
- DYNAMODB_REGION=ap-south-1
- DYNAMODB_ACCESS_KEY=local
- DYNAMODB_SECRET_KEY=local
- env_file = ./.env.local
volumes:
dynamodb_data:
external: true
16 changes: 9 additions & 7 deletions generate_table/__main__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os

import boto3
from dotenv import load_dotenv
from student_quiz_reports import (
generate_student_quiz_reports,
drop_student_quiz_reports,
add_secondary_index,
drop_secondary_index,
drop_student_quiz_reports,
generate_student_quiz_reports_v2,
)
from dotenv import load_dotenv
import boto3
import os

# Update and use `.env.prod` to write to prod dynamodb table
# or use `.env.staging` to write to staging dynamodb table
Expand All @@ -23,6 +24,7 @@ def initialize_db():
aws_secret_access_key=os.environ.get("DYNAMODB_SECRET_KEY"),
)

print(os.environ.get("DYNAMODB_URL"))
return ddb


Expand All @@ -31,7 +33,7 @@ def generate_tables():
Generates all required dynamodb table (for now only student_quiz_reports)
"""
ddb = initialize_db()
generate_student_quiz_reports(ddb)
generate_student_quiz_reports_v2(ddb)


def drop_tables():
Expand Down Expand Up @@ -60,4 +62,4 @@ def drop_secondary_ind(index_name: str):
Creates empty dynamodb table with correct schema for local usage.
"""
generate_tables()
add_secondary_ind()
# add_secondary_ind()
22 changes: 22 additions & 0 deletions generate_table/student_quiz_reports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
def generate_student_quiz_reports(ddb):
"""
Adds student quiz report table (v1)
"""
ddb.create_table(
TableName="student_quiz_reports",
AttributeDefinitions=[
Expand All @@ -14,6 +17,25 @@ def generate_student_quiz_reports(ddb):
print("Successfully created Student Quiz Reports Table")


def generate_student_quiz_reports_v2(ddb):
"""
Adds student quiz report table (v1)
"""
ddb.create_table(
TableName="student_quiz_reports_v2",
AttributeDefinitions=[
{"AttributeName": "user_id", "AttributeType": "S"},
{"AttributeName": "session_id", "AttributeType": "S"},
],
KeySchema=[
{"AttributeName": "session_id", "KeyType": "HASH"},
{"AttributeName": "user_id", "KeyType": "RANGE"},
],
BillingMode="PAY_PER_REQUEST",
)
print("Successfully created Student Quiz Reports Table")


def add_secondary_index(ddb):
table = ddb.Table("student_quiz_reports")
response = table.update(
Expand Down
4 changes: 4 additions & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"venvPath": ".",
"venv": "env"
}

0 comments on commit 04b7a0e

Please sign in to comment.