fix: DatabaseManager removes inline comments correctly in migrations

- Fixed SQL statement parsing to remove both line and inline comments
- Prevents incomplete SQL statements from inline comments
- Migration 005 and 006 now apply correctly via automatic migration system
- Tested with production data: All 72 groups have display_in_workshop = 0 (GDPR compliant)
This commit is contained in:
Matthias Lotz 2025-11-10 17:45:32 +01:00
parent f049c47f38
commit 8e6247563a

View File

@ -361,11 +361,24 @@ class DatabaseManager {
// Execute migration in a transaction
await this.run('BEGIN TRANSACTION');
// Remove comments (both line and inline) before splitting
const cleanedSql = sql
.split('\n')
.map(line => {
// Remove inline comments (everything after --)
const commentIndex = line.indexOf('--');
if (commentIndex !== -1) {
return line.substring(0, commentIndex);
}
return line;
})
.join('\n');
// Split by semicolon and execute each statement
const statements = sql
const statements = cleanedSql
.split(';')
.map(s => s.trim())
.filter(s => s.length > 0 && !s.startsWith('--'));
.filter(s => s.length > 0);
for (const statement of statements) {
await this.run(statement);