Skip to content

Add backend production readiness improvements - #13

Merged
tukue merged 8 commits into
mainfrom
backend-development-best-practices
Jul 6, 2026
Merged

tukue merged 8 commits into
mainfrom
backend-development-best-practices

Conversation

@tukue

@tukue tukue commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Short description of the change and the problem it solves.

Changes

  • List of major changes

Checklist

  • Tests added/updated
  • Lint and format checks passed (npm run lint && npm run format:check)
  • Relevant documentation updated
  • Database migrations added (if applicable)

Notes

Any additional notes for reviewers, deployment steps, or rollbacks.

@gitguardian

gitguardian Bot commented Jul 6, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
23517139 Triggered Generic Password 4f83623 .github/workflows/ci.yml View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

This PR introduces backend production readiness improvements including database migrations, model validations, and infrastructure changes. However, there are 3 critical blocking issues that must be fixed before merge:

Critical Issues Found

  1. SQL Injection Vulnerability in scripts/migrate.js - Unsanitized table name in query allows potential SQL injection
  2. Runtime Error in migrations/20260706000100-create-core-tables.js - Inconsistent timestamp column naming between orders table (camelCase) and other tables (snake_case) will break Sequelize model functionality
  3. Dockerfile CMD Error in the migration error handling that could cause silent failures

Positive Changes

  • Proper migration system implementation with tracking
  • Addition of model-level validations for Order fields
  • Replacement of sequelize.sync() with proper database connection check
  • Graceful shutdown handling improvements

Please address the critical issues identified in the inline comments before merging.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread scripts/migrate.js Outdated
}

async function getAppliedMigrations() {
const [rows] = await sequelize.query(`SELECT name FROM ${metaTable}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: SQL injection risk with unsanitized table name in query. The metaTable variable is directly interpolated into the SQL query without parameterization, allowing potential SQL injection if the table name could be controlled or modified.

Suggested change
const [rows] = await sequelize.query(`SELECT name FROM ${metaTable}`);
const [rows] = await sequelize.query('SELECT name FROM ?? ORDER BY name', {
replacements: [metaTable],
type: sequelize.QueryTypes.SELECT
});
return new Set(rows.map((row) => row.name));

Comment on lines +120 to +129
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Logic Error: Inconsistent timestamp column naming will cause runtime errors. Orders table uses camelCase (createdAt/updatedAt) while other tables use snake_case (created_at/updated_at). Sequelize models expect consistent naming conventions, and this mismatch will break the Order model's timestamp functionality.

Suggested change
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},

Comment thread Dockerfile Outdated
USER nodeuser

CMD ["node", "server.js"]
CMD ["sh", "-c", "npm run migrate && node server.js"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Crash Risk: Running migrations in the CMD without proper error handling will cause the container to crash silently if migrations fail. The shell command uses && which will proceed to start the server even if migrations fail with non-zero exit codes. This can lead to runtime errors when the server expects tables that don't exist.

Suggested change
CMD ["sh", "-c", "npm run migrate && node server.js"]
CMD ["sh", "-c", "npm run migrate || exit 1; node server.js"]

@tukue
tukue merged commit bc17018 into main Jul 6, 2026
6 of 7 checks passed
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