-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: automatic db migrations #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,20 @@ | ||||||||||||||||||||
'use strict'; | ||||||||||||||||||||
|
||||||||||||||||||||
module.exports = { | ||||||||||||||||||||
up: async (queryInterface, Sequelize) => { | ||||||||||||||||||||
const tableInfo = await queryInterface.describeTable('run'); | ||||||||||||||||||||
|
||||||||||||||||||||
// Only add the column if it doesn't exist | ||||||||||||||||||||
if (!tableInfo.retryCount) { | ||||||||||||||||||||
await queryInterface.addColumn('run', 'retryCount', { | ||||||||||||||||||||
type: Sequelize.INTEGER, | ||||||||||||||||||||
allowNull: true, | ||||||||||||||||||||
defaultValue: 0, | ||||||||||||||||||||
}); | ||||||||||||||||||||
} | ||||||||||||||||||||
}, | ||||||||||||||||||||
|
||||||||||||||||||||
down: async (queryInterface, Sequelize) => { | ||||||||||||||||||||
await queryInterface.removeColumn('run', 'retryCount'); | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Make the down migration idempotent. The down migration unconditionally removes the Apply this diff to make the down migration idempotent: down: async (queryInterface, Sequelize) => {
- await queryInterface.removeColumn('run', 'retryCount');
+ const tableInfo = await queryInterface.describeTable('run');
+ if (tableInfo.retryCount) {
+ await queryInterface.removeColumn('run', 'retryCount');
+ }
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider failing fast on migration errors.
The script continues to start the server even if migrations fail (line 36). This could lead to runtime errors if the schema is out of sync with the application code (e.g., missing
retryCount
column).Consider changing the behavior to exit on migration failure to prevent cascading errors:
Alternatively, if continuing on failure is intentional (e.g., for local development), document the rationale in a comment.
📝 Committable suggestion
🤖 Prompt for AI Agents