mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cae2b83649 |
@@ -65,7 +65,7 @@ export async function initializeDatabase(): Promise<void> {
|
||||
|
||||
console.log('Existing tables found:', existingTables.map(t => t.name).join(', ') || 'none');
|
||||
|
||||
// UPDATED: Drop tables in correct dependency order for new schema
|
||||
// Drop tables in correct dependency order for new schema
|
||||
const tablesToDrop = [
|
||||
'employee_availability',
|
||||
'shift_assignments',
|
||||
@@ -95,16 +95,40 @@ export async function initializeDatabase(): Promise<void> {
|
||||
// Continue with schema creation even if table dropping fails
|
||||
}
|
||||
|
||||
// Execute schema creation in a transaction
|
||||
await db.run('BEGIN EXCLUSIVE TRANSACTION');
|
||||
|
||||
// Execute each statement separately for better error reporting
|
||||
const statements = schema
|
||||
// NEU: PRAGMA-Anweisungen außerhalb der Transaktion ausführen
|
||||
console.log('Executing PRAGMA statements outside transaction...');
|
||||
const pragmaStatements = schema
|
||||
.split(';')
|
||||
.map(stmt => stmt.trim())
|
||||
.filter(stmt => stmt.length > 0)
|
||||
.filter(stmt => stmt.toUpperCase().startsWith('PRAGMA'))
|
||||
.map(stmt => {
|
||||
return stmt.split('\n')
|
||||
.filter(line => !line.trim().startsWith('--'))
|
||||
.join('\n')
|
||||
.trim();
|
||||
});
|
||||
|
||||
for (const statement of pragmaStatements) {
|
||||
try {
|
||||
console.log('Executing PRAGMA:', statement);
|
||||
await db.run(statement);
|
||||
} catch (error) {
|
||||
console.warn('PRAGMA statement might have failed:', statement, error);
|
||||
// Continue even if PRAGMA fails
|
||||
}
|
||||
}
|
||||
|
||||
// Schema-Erstellung in Transaktion
|
||||
await db.run('BEGIN EXCLUSIVE TRANSACTION');
|
||||
|
||||
// Nur die CREATE TABLE und andere Anweisungen (ohne PRAGMA)
|
||||
const schemaStatements = schema
|
||||
.split(';')
|
||||
.map(stmt => stmt.trim())
|
||||
.filter(stmt => stmt.length > 0)
|
||||
.filter(stmt => !stmt.toUpperCase().startsWith('PRAGMA'))
|
||||
.map(stmt => {
|
||||
// Remove any single-line comments
|
||||
return stmt.split('\n')
|
||||
.filter(line => !line.trim().startsWith('--'))
|
||||
.join('\n')
|
||||
@@ -112,7 +136,7 @@ export async function initializeDatabase(): Promise<void> {
|
||||
})
|
||||
.filter(stmt => stmt.length > 0);
|
||||
|
||||
for (const statement of statements) {
|
||||
for (const statement of schemaStatements) {
|
||||
try {
|
||||
console.log('Executing statement:', statement.substring(0, 50) + '...');
|
||||
await db.run(statement);
|
||||
@@ -124,7 +148,7 @@ export async function initializeDatabase(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATED: Insert default data in correct order
|
||||
// Insert default data in correct order
|
||||
try {
|
||||
console.log('Inserting default employee types...');
|
||||
await db.run(`INSERT OR IGNORE INTO employee_types (type, category, has_contract_type) VALUES ('manager', 'internal', 1)`);
|
||||
|
||||
Reference in New Issue
Block a user