Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions migrations/V142__add_altcha_challenge_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE altcha_challenge (
challenge VARCHAR(64) NOT NULL,
expires_at DATETIME NOT NULL,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find how expiration/time columns are modeled in other migrations
rg -n --type-add 'sql:*.sql' --type sql -C2 '\b(expires_at|expire|expiration|TIMESTAMP|DATETIME)\b' migrations

Repository: FAForever/db

Length of output: 2878


🏁 Script executed:

#!/bin/bash
# Search for cleanup queries or queries filtering by expiration
rg -n 'expires_at\s*[<>=]' --type-add 'sql:*.sql' --type sql migrations

Repository: FAForever/db

Length of output: 38


🏁 Script executed:

#!/bin/bash
# Also check application code for altcha_challenge queries
rg -n 'altcha_challenge' --type-list | head -20
rg -rn 'altcha' --type-add 'ts:*.ts' --type-add 'js:*.js' -A 3 -B 3 2>/dev/null | head -50

Repository: FAForever/db

Length of output: 773


🏁 Script executed:

#!/bin/bash
# Check the full migration file to understand context
cat migrations/V142__add_altcha_challenge_table.sql

Repository: FAForever/db

Length of output: 182


🏁 Script executed:

#!/bin/bash
# Search for altcha references in the entire repository (outside migrations)
find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.py" -o -name "*.java" \) ! -path "./migrations/*" -exec grep -l "altcha" {} \; 2>/dev/null | head -20

Repository: FAForever/db

Length of output: 38


🏁 Script executed:

#!/bin/bash
# Check repository structure to find application code
ls -la | grep -E '^d'
find . -maxdepth 2 -type d -name "src" -o -name "app" -o -name "server" -o -name "backend" 2>/dev/null

Repository: FAForever/db

Length of output: 507


🏁 Script executed:

#!/bin/bash
# Search for any expiration cleanup patterns in the codebase to see if this pattern is used elsewhere
rg -n 'WHERE.*<\s*(CURRENT|NOW|UNIX_TIMESTAMP)' --type-add 'sql:*.sql' --type sql 2>/dev/null | head -20

Repository: FAForever/db

Length of output: 38


Add an index on expires_at and align timestamp column type with project convention.

This table uses DATETIME for expiration, but the codebase mixes DATETIME and TIMESTAMP (see avatar table uses TIMESTAMP, ban table uses DATETIME). Clarify which convention applies and ensure consistency. Additionally, if the application code queries expired challenges with WHERE expires_at < ..., an index on this column will prevent full table scans.

💡 Proposed migration adjustment
 CREATE TABLE altcha_challenge (
   challenge VARCHAR(64) NOT NULL,
   expires_at DATETIME NOT NULL,
   PRIMARY KEY (challenge)
 );
+
+CREATE INDEX idx_altcha_challenge_expires_at
+  ON altcha_challenge (expires_at);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expires_at DATETIME NOT NULL,
CREATE TABLE altcha_challenge (
challenge VARCHAR(64) NOT NULL,
expires_at DATETIME NOT NULL,
PRIMARY KEY (challenge)
);
CREATE INDEX idx_altcha_challenge_expires_at
ON altcha_challenge (expires_at);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@migrations/V142__add_altcha_challenge_table.sql` at line 3, The migration
defines expires_at as DATETIME on the altcha_challenge table and lacks an index;
update the migration so the expires_at column uses the project-convention
timestamp type (use TIMESTAMP NOT NULL to match avatar/other tables) and add an
index on expires_at (e.g., CREATE INDEX on altcha_challenge(expires_at) or
include INDEX expires_at in the CREATE TABLE) so queries like WHERE expires_at <
... can use the index; modify the V142__add_altcha_challenge_table.sql migration
accordingly referencing the altcha_challenge table and expires_at column.

PRIMARY KEY (challenge)
);

CREATE INDEX idx_altcha_challenge_expires_at ON altcha_challenge (expires_at);