Stop Sequelize schema-altering sync during app boot; require explicit setup sync - #217
Merged
Merged
Conversation
Copilot created this pull request from a session on behalf of
jiayangc1
July 9, 2026 05:29
View session
jiayangc1
marked this pull request as ready for review
July 9, 2026 05:29
There was a problem hiding this comment.
Pull request overview
This PR prevents runtime application startup from performing Sequelize schema-altering DDL by default, moving sequelize.sync({ alter: true }) behind an explicit, opt-in setup flow to avoid lock exhaustion under clustered/parallel boots.
Changes:
- Updated
initDatabaseto accept options ({ sync, alter }) and default to authenticate-only behavior. - Gated model syncing behind an explicit
sync: trueoption. - Updated
setup-db.jsto explicitly request schema sync + alter during the setup script.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
models/index.js |
Makes DB initialization authenticate-only by default; sync/alter now opt-in via options. |
setup-db.js |
Explicitly opts into schema sync/alter for the setup script entrypoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| console.log("✅ Database models synchronized successfully."); | ||
| } | ||
| } catch (error) { | ||
| console.error("❌ Unable to connect to the database:", error); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under clustered PM2 startup, each worker was executing
sequelize.sync({ alter: true }), triggering concurrentALTER TABLEDDL and exhausting PostgreSQL locks (53200: out of shared memory). This change makes runtime boot authenticate-only and moves schema alteration to explicit setup flow.Database init contract (
models/index.js)initDatabasenow accepts options:initDatabase({ sync = false, alter = false } = {}).syncis explicitly enabled.Explicit schema setup path (
setup-db.js)initDatabase({ sync: true, alter: true }).Runtime impact
node .no longer performs schema-altering DDL during startup.node setup-db.jsremains the explicit entrypoint for schema sync/alter.