Skip to content

Feature/submission module#4

Open
Aneeshie wants to merge 2 commits into
mainfrom
feature/submission-module
Open

Feature/submission module#4
Aneeshie wants to merge 2 commits into
mainfrom
feature/submission-module

Conversation

@Aneeshie

@Aneeshie Aneeshie commented Mar 9, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added support for submission tracking with status monitoring and verdict results.
  • Chores

    • Updated database service port configuration.
  • Style

    • Code formatting improvements.

@coderabbitai

coderabbitai Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes add a new database migration to create a submissions table with associated enum types for tracking submission verdicts and status. Additionally, the docker-compose configuration updates the PostgreSQL port binding, and a minor formatting adjustment is made to the Go main function signature.

Changes

Cohort / File(s) Summary
Code Formatting
cmd/server/main.go
Whitespace normalization: added space before opening brace in main function signature.
Docker Configuration
docker-compose.yml
Updated PostgreSQL service port binding from 5432:5432 to 5433:5432; reformatted healthcheck array syntax with consistent spacing.
Database Migrations
migrations/20260309034612_create-submission_table.down.sql, migrations/20260309034612_create-submission_table.up.sql
New migration pair: up migration creates verdict and submission_status enum types, submissions table with columns for problem_id, user_id, code, language, status, verdict, and created_at; includes index on problem_id. Down migration drops table and enum types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A submission table hops into place,

With verdicts and statuses keeping the pace,

Enums for accepted or errors so dire,

Docker listens on 5433, reaching up higher! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feature/submission module' accurately describes the main change: introducing a new submission module with database schema, migrations, and configuration updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/submission-module

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@migrations/20260309034612_create-submission_table.up.sql`:
- Around line 26-27: Add a CHECK constraint on the submissions table to enforce
the state machine between the status and verdict columns (submission_status and
verdict): require verdict IS NOT NULL when status = 'completed' and require
verdict IS NULL for all non-completed statuses; add a descriptive constraint
name (e.g., submissions_status_verdict_check) in the migration so the database
rejects impossible combinations like status = 'completed' with NULL verdict or
status != 'completed' with a terminal verdict.
- Line 21: The submissions migration defines user_id as a plain BIGINT which
lacks referential integrity; either create the users table in an earlier
migration or change the submissions table definition so user_id enforces a
foreign key (e.g., user_id BIGINT NOT NULL REFERENCES users(id)) and match any
nullability you want; update the CREATE TABLE for submissions (the user_id
column) or add a separate ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY
(user_id) REFERENCES users(id) once users exists so submissions.user_id
references users(id) like problem_id references problems(id).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c11cb7d-6315-4bab-a905-8bc57a1eedb6

📥 Commits

Reviewing files that changed from the base of the PR and between a2c6d75 and 6d4f40a.

📒 Files selected for processing (4)
  • cmd/server/main.go
  • docker-compose.yml
  • migrations/20260309034612_create-submission_table.down.sql
  • migrations/20260309034612_create-submission_table.up.sql


problem_id BIGINT NOT NULL REFERENCES problems(id),

user_id BIGINT,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether the schema already defines a users table and how `user_id` is modeled elsewhere.
rg -n -C3 'CREATE TABLE users|REFERENCES users\s*\(' migrations
rg -n -C3 '\buser_id\b' migrations internal

Repository: Aneeshie/CPPJudge

Length of output: 611


🏁 Script executed:

# Search entire repository for users table creation and definition
find . -type f -name "*.sql" | head -20
rg -i 'create table.*users' .
rg -i 'create table' migrations | sort

Repository: Aneeshie/CPPJudge

Length of output: 459


🏁 Script executed:

# Also check the full migration file to understand context
cat -n migrations/20260309034612_create-submission_table.up.sql

Repository: Aneeshie/CPPJudge

Length of output: 901


🏁 Script executed:

# Search entire repo for any reference to users table
rg -i 'users' . --type sql
git ls-files | grep -E '\.(sql|md|txt)$'

Repository: Aneeshie/CPPJudge

Length of output: 298


🏁 Script executed:

cat README.md

Repository: Aneeshie/CPPJudge

Length of output: 1346


Add foreign key constraint to user_id or create users table first.

The user_id field is defined as a bare BIGINT without a foreign key constraint, unlike problem_id which references problems(id). Since a users table does not yet exist in migrations, submissions can reference non-existent user IDs, allowing orphan records and breaking referential integrity. Either create a users table migration first, or add NOT NULL REFERENCES users(id) to user_id when the users table is added.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@migrations/20260309034612_create-submission_table.up.sql` at line 21, The
submissions migration defines user_id as a plain BIGINT which lacks referential
integrity; either create the users table in an earlier migration or change the
submissions table definition so user_id enforces a foreign key (e.g., user_id
BIGINT NOT NULL REFERENCES users(id)) and match any nullability you want; update
the CREATE TABLE for submissions (the user_id column) or add a separate ALTER
TABLE ... ADD CONSTRAINT ... FOREIGN KEY (user_id) REFERENCES users(id) once
users exists so submissions.user_id references users(id) like problem_id
references problems(id).

Comment on lines +26 to +27
status submission_status NOT NULL DEFAULT 'pending',
verdict verdict,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Enforce the status/verdict state machine in the schema.

Right now this table accepts impossible combinations like status = 'completed' with verdict IS NULL, or status = 'pending' with a terminal verdict. That will leak inconsistent rows into every reader of submissions.

Suggested constraint
 CREATE TABLE submissions (
     id BIGSERIAL PRIMARY KEY,

     problem_id BIGINT NOT NULL REFERENCES problems(id),

     user_id BIGINT,

     code TEXT NOT NULL,
     language TEXT NOT NULL,

     status submission_status NOT NULL DEFAULT 'pending',
     verdict verdict,
+    CONSTRAINT submissions_status_verdict_check CHECK (
+        (status IN ('pending', 'running') AND verdict IS NULL) OR
+        (status = 'completed' AND verdict IS NOT NULL)
+    ),

     created_at TIMESTAMP DEFAULT NOW()
 );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@migrations/20260309034612_create-submission_table.up.sql` around lines 26 -
27, Add a CHECK constraint on the submissions table to enforce the state machine
between the status and verdict columns (submission_status and verdict): require
verdict IS NOT NULL when status = 'completed' and require verdict IS NULL for
all non-completed statuses; add a descriptive constraint name (e.g.,
submissions_status_verdict_check) in the migration so the database rejects
impossible combinations like status = 'completed' with NULL verdict or status !=
'completed' with a terminal verdict.

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.

1 participant