소스 검색

Fix backend startup: stop using alter:true for SQLite sync

Sequelize's alter:true on SQLite drops and recreates tables to change
columns, which fails with a FK constraint error when other tables
reference the one being altered (e.g. DROP TABLE users). Beyond the FK
error, dropping live tables is unsafe regardless.

Switch to plain sync() which only creates tables that don't exist and
never touches existing schema. Schema migrations for new columns must
be handled explicitly if needed in the future.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
k4be 12 시간 전
부모
커밋
b6d88abb99
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      gpx-vis-backend/src/database.js

+ 4 - 1
gpx-vis-backend/src/database.js

@@ -31,7 +31,10 @@ async function initDatabase() {
   // Import models to register them
   require('./models');
   const isMemory = (config.database?.storage === ':memory:');
-  await sq.sync(isMemory ? {} : { alter: true });
+  // sync() creates missing tables without touching existing ones.
+  // alter:true is intentionally avoided: on SQLite it drops and recreates
+  // tables to change columns, which destroys data and breaks FK constraints.
+  await sq.sync(isMemory ? {} : {});
   console.log('Database initialized');
 }