removed phone and departement as user attribute

This commit is contained in:
2025-10-10 18:22:13 +02:00
parent 6a9ddea0c5
commit e1e435a811
21 changed files with 1508 additions and 888 deletions

View File

@@ -0,0 +1,43 @@
import { db } from '../services/databaseService.js';
import { readFile } from 'fs/promises';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export async function applyMigration() {
try {
console.log('📦 Starting database migration...');
// Read the migration file
const migrationPath = join(__dirname, '../database/migrations/002_add_employee_fields.sql');
const migrationSQL = await readFile(migrationPath, 'utf-8');
// Split into individual statements
const statements = migrationSQL
.split(';')
.map(s => s.trim())
.filter(s => s.length > 0);
// Execute each statement
for (const statement of statements) {
try {
await db.exec(statement);
console.log('✅ Executed:', statement.slice(0, 50) + '...');
} catch (error) {
const err = error as { code: string; message: string };
if (err.code === 'SQLITE_ERROR' && err.message.includes('duplicate column name')) {
console.log(' Column already exists, skipping...');
continue;
}
throw error;
}
}
console.log('✅ Migration completed successfully');
} catch (error) {
console.error('❌ Migration failed:', error);
throw error;
}
}

View File

@@ -1,92 +0,0 @@
// backend/src/scripts/seedData.ts - Erweitert
import { db } from '../services/databaseService.js';
import { v4 as uuidv4 } from 'uuid';
import bcrypt from 'bcryptjs';
export const seedData = async () => {
try {
console.log('Starting database seeding...');
// Admin User erstellen
const adminId = uuidv4();
const hashedPassword = await bcrypt.hash('admin123', 10);
await db.run(
`INSERT OR IGNORE INTO users (id, email, password, name, role, phone, department, is_active)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
[adminId, 'admin@schichtplan.de', hashedPassword, 'System Administrator', 'admin', '+49 123 456789', 'IT', 1]
);
// Test-Mitarbeiter erstellen
const testUsers = [
{
id: uuidv4(),
email: 'instandhalter@schichtplan.de',
password: await bcrypt.hash('instandhalter123', 10),
name: 'Max Instandhalter',
role: 'instandhalter',
phone: '+49 123 456790',
department: 'Produktion'
},
{
id: uuidv4(),
email: 'mitarbeiter1@schichtplan.de',
password: await bcrypt.hash('user123', 10),
name: 'Anna Müller',
role: 'user',
phone: '+49 123 456791',
department: 'Logistik'
},
{
id: uuidv4(),
email: 'mitarbeiter2@schichtplan.de',
password: await bcrypt.hash('user123', 10),
name: 'Tom Schmidt',
role: 'user',
phone: '+49 123 456792',
department: 'Produktion'
}
];
for (const user of testUsers) {
await db.run(
`INSERT OR IGNORE INTO users (id, email, password, name, role, phone, department, is_active)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
[user.id, user.email, user.password, user.name, user.role, user.phone, user.department, 1]
);
}
// Standard Vorlage erstellen
const templateId = uuidv4();
await db.run(
`INSERT OR IGNORE INTO shift_templates (id, name, description, is_default, created_by)
VALUES (?, ?, ?, ?, ?)`,
[templateId, 'Standard Woche', 'Standard Schichtplan für Montag bis Freitag', 1, adminId]
);
// Standard Schichten
const shifts = [
{ day: 1, name: 'Vormittag', start: '08:00', end: '12:00', employees: 2 },
{ day: 1, name: 'Nachmittag', start: '11:30', end: '15:30', employees: 2 },
{ day: 2, name: 'Vormittag', start: '08:00', end: '12:00', employees: 2 },
{ day: 2, name: 'Nachmittag', start: '11:30', end: '15:30', employees: 2 },
{ day: 3, name: 'Vormittag', start: '08:00', end: '12:00', employees: 2 },
{ day: 3, name: 'Nachmittag', start: '11:30', end: '15:30', employees: 2 },
{ day: 4, name: 'Vormittag', start: '08:00', end: '12:00', employees: 2 },
{ day: 4, name: 'Nachmittag', start: '11:30', end: '15:30', employees: 2 },
{ day: 5, name: 'Vormittag', start: '08:00', end: '12:00', employees: 2 }
];
for (const shift of shifts) {
await db.run(
`INSERT OR IGNORE INTO template_shifts (id, template_id, day_of_week, name, start_time, end_time, required_employees)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
[uuidv4(), templateId, shift.day, shift.name, shift.start, shift.end, shift.employees]
);
}
console.log('✅ Test data seeded successfully');
} catch (error) {
console.error('❌ Error seeding test data:', error);
}
};