Przeglądaj źródła

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 godzin temu
rodzic
commit
b6d88abb99
1 zmienionych plików z 4 dodań i 1 usunięć
  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');
 }