feat: Einführung von Umgebungsvariablen und Startskripten für die Backend-Anwendung
- Hinzufügen eines zentralen Skripts zum Laden von Umgebungsvariablen aus einer .env-Datei. - Implementierung von Start- und Entwicklungs-Skripten in der package.json für eine vereinfachte Ausführung der Anwendung. - Bereinigung und Entfernung nicht mehr benötigter Minigame-Modelle und -Services zur Verbesserung der Codebasis. - Anpassungen an den Datenbankmodellen zur Unterstützung von neuen Assoziationen und zur Verbesserung der Lesbarkeit.
This commit is contained in:
@@ -8,7 +8,11 @@ async function cleanupDatabaseConstraints() {
|
||||
try {
|
||||
console.log('🧹 Starte Bereinigung der Datenbank-Constraints...');
|
||||
|
||||
// 1. Doppelte UNIQUE Constraints entfernen
|
||||
// 1. Spezielle Bereinigung für community.user Tabelle
|
||||
console.log('🔍 Spezielle Bereinigung für community.user Tabelle...');
|
||||
await cleanupUserTableConstraints();
|
||||
|
||||
// 2. Doppelte UNIQUE Constraints entfernen
|
||||
console.log('🔍 Suche nach doppelten UNIQUE Constraints...');
|
||||
|
||||
const duplicateUniqueConstraints = await sequelize.query(`
|
||||
@@ -50,7 +54,11 @@ async function cleanupDatabaseConstraints() {
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Doppelte CHECK Constraints entfernen (korrigierte Abfrage)
|
||||
// 3. Entferne alle Constraints mit numerischen Suffixen
|
||||
console.log('🔍 Entferne alle Constraints mit numerischen Suffixen...');
|
||||
await removeNumericalSuffixConstraints();
|
||||
|
||||
// 4. Doppelte CHECK Constraints entfernen (korrigierte Abfrage)
|
||||
console.log('🔍 Suche nach doppelten CHECK Constraints...');
|
||||
|
||||
try {
|
||||
@@ -72,7 +80,7 @@ async function cleanupDatabaseConstraints() {
|
||||
console.log(`⚠️ Konnte CHECK Constraints nicht abfragen: ${error.message}`);
|
||||
}
|
||||
|
||||
// 3. Doppelte Foreign Key Constraints entfernen
|
||||
// 5. Doppelte Foreign Key Constraints entfernen
|
||||
console.log('🔍 Suche nach doppelten Foreign Key Constraints...');
|
||||
|
||||
const duplicateFKs = await sequelize.query(`
|
||||
@@ -95,7 +103,7 @@ async function cleanupDatabaseConstraints() {
|
||||
|
||||
console.log(`📊 Gefunden: ${duplicateFKs.length} Foreign Key Constraints`);
|
||||
|
||||
// 4. Doppelte Indexe entfernen
|
||||
// 6. Doppelte Indexe entfernen
|
||||
console.log('🔍 Suche nach doppelten Indexen...');
|
||||
|
||||
const duplicateIndexes = await sequelize.query(`
|
||||
@@ -112,7 +120,7 @@ async function cleanupDatabaseConstraints() {
|
||||
|
||||
console.log(`📊 Gefunden: ${duplicateIndexes.length} potenziell doppelte Indexe`);
|
||||
|
||||
// 5. Spezifische Match3-Constraints prüfen
|
||||
// 7. Spezifische Match3-Constraints prüfen
|
||||
console.log('🔍 Prüfe Match3-spezifische Constraints...');
|
||||
|
||||
const match3Constraints = await sequelize.query(`
|
||||
@@ -130,7 +138,7 @@ async function cleanupDatabaseConstraints() {
|
||||
console.log(` - ${constraint.table_name}: ${constraint.constraint_type} (${constraint.constraint_name})`);
|
||||
});
|
||||
|
||||
// 6. Spezifische Chat-Constraints prüfen (da das Problem dort auftritt)
|
||||
// 8. Spezifische Chat-Constraints prüfen (da das Problem dort auftritt)
|
||||
console.log('🔍 Prüfe Chat-spezifische Constraints...');
|
||||
|
||||
try {
|
||||
@@ -155,7 +163,7 @@ async function cleanupDatabaseConstraints() {
|
||||
console.log(`⚠️ Konnte Chat Constraints nicht abfragen: ${error.message}`);
|
||||
}
|
||||
|
||||
// 7. Spezifische Überprüfung der chat.rights Tabelle
|
||||
// 9. Spezifische Überprüfung der chat.rights Tabelle
|
||||
console.log('🔍 Spezielle Überprüfung der chat.rights Tabelle...');
|
||||
|
||||
try {
|
||||
@@ -203,7 +211,7 @@ async function cleanupDatabaseConstraints() {
|
||||
console.log(`⚠️ Konnte chat.rights Constraints nicht abfragen: ${error.message}`);
|
||||
}
|
||||
|
||||
// 8. Empfehlungen ausgeben
|
||||
// 10. Empfehlungen ausgeben
|
||||
console.log('\n💡 Empfehlungen:');
|
||||
console.log('1. Überprüfe die oben gelisteten Constraints auf Duplikate');
|
||||
console.log('2. Verwende updateSchema() nur bei expliziten Schema-Änderungen');
|
||||
@@ -218,6 +226,133 @@ async function cleanupDatabaseConstraints() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spezielle Bereinigung für die community.user Tabelle
|
||||
* Entfernt alle Constraints mit numerischen Suffixen
|
||||
*/
|
||||
async function cleanupUserTableConstraints() {
|
||||
try {
|
||||
console.log('🔍 Bereinige community.user Tabelle...');
|
||||
|
||||
// Finde alle Constraints der user Tabelle
|
||||
const userConstraints = await sequelize.query(`
|
||||
SELECT
|
||||
tc.constraint_name,
|
||||
tc.constraint_type,
|
||||
kcu.column_name
|
||||
FROM information_schema.table_constraints tc
|
||||
LEFT JOIN information_schema.key_column_usage kcu
|
||||
ON tc.constraint_name = kcu.constraint_name
|
||||
WHERE tc.table_schema = 'community'
|
||||
AND tc.table_name = 'user'
|
||||
ORDER BY tc.constraint_type, kcu.column_name;
|
||||
`, { type: sequelize.QueryTypes.SELECT });
|
||||
|
||||
console.log(`📊 Community.user Constraints gefunden: ${userConstraints.length}`);
|
||||
|
||||
// Gruppiere Constraints nach Spalte und Typ
|
||||
const constraintsByColumn = {};
|
||||
userConstraints.forEach(constraint => {
|
||||
const key = `${constraint.constraint_type}_${constraint.column_name || 'general'}`;
|
||||
if (!constraintsByColumn[key]) {
|
||||
constraintsByColumn[key] = [];
|
||||
}
|
||||
constraintsByColumn[key].push(constraint.constraint_name);
|
||||
});
|
||||
|
||||
// Entferne doppelte Constraints, behalte nur einen pro Spalte/Typ
|
||||
for (const [key, constraintNames] of Object.entries(constraintsByColumn)) {
|
||||
if (constraintNames.length > 1) {
|
||||
console.log(`🗑️ Entferne ${constraintNames.length - 1} doppelte Constraints für ${key}`);
|
||||
|
||||
// Sortiere nach Namen, um konsistente Ergebnisse zu erhalten
|
||||
constraintNames.sort();
|
||||
|
||||
// Behalte den ersten, entferne die anderen
|
||||
for (let i = 1; i < constraintNames.length; i++) {
|
||||
const constraintName = constraintNames[i];
|
||||
try {
|
||||
await sequelize.query(`
|
||||
ALTER TABLE community."user"
|
||||
DROP CONSTRAINT IF EXISTS "${constraintName}"
|
||||
`);
|
||||
console.log(` ✅ Entfernt: ${constraintName}`);
|
||||
} catch (error) {
|
||||
console.log(` ⚠️ Konnte nicht entfernen: ${constraintName} - ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Entferne alle Constraints mit numerischen Suffixen
|
||||
const numericalConstraints = userConstraints.filter(c =>
|
||||
/\d+$/.test(c.constraint_name) &&
|
||||
(c.constraint_name.includes('_key') || c.constraint_name.includes('_index'))
|
||||
);
|
||||
|
||||
if (numericalConstraints.length > 0) {
|
||||
console.log(`🗑️ Entferne ${numericalConstraints.length} Constraints mit numerischen Suffixen`);
|
||||
|
||||
for (const constraint of numericalConstraints) {
|
||||
try {
|
||||
await sequelize.query(`
|
||||
ALTER TABLE community."user"
|
||||
DROP CONSTRAINT IF EXISTS "${constraint.constraint_name}"
|
||||
`);
|
||||
console.log(` ✅ Entfernt: ${constraint.constraint_name}`);
|
||||
} catch (error) {
|
||||
console.log(` ⚠️ Konnte nicht entfernen: ${constraint.constraint_name} - ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(`⚠️ Konnte community.user Constraints nicht bereinigen: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entfernt alle Constraints mit numerischen Suffixen aus allen Tabellen
|
||||
*/
|
||||
async function removeNumericalSuffixConstraints() {
|
||||
try {
|
||||
console.log('🔍 Entferne alle Constraints mit numerischen Suffixen...');
|
||||
|
||||
// Finde alle Constraints mit numerischen Suffixen
|
||||
const numericalConstraints = await sequelize.query(`
|
||||
SELECT
|
||||
tc.table_schema,
|
||||
tc.table_name,
|
||||
tc.constraint_name,
|
||||
tc.constraint_type
|
||||
FROM information_schema.table_constraints tc
|
||||
WHERE tc.table_schema IN ('match3', 'community', 'falukant_data', 'falukant_type', 'falukant_predefine', 'falukant_log', 'chat', 'forum', 'logs', 'type', 'service')
|
||||
AND tc.constraint_name ~ '.*\\d+$'
|
||||
AND (tc.constraint_name LIKE '%_key%' OR tc.constraint_name LIKE '%_index%')
|
||||
ORDER BY tc.table_schema, tc.table_name, tc.constraint_name;
|
||||
`, { type: sequelize.QueryTypes.SELECT });
|
||||
|
||||
console.log(`📊 Gefunden: ${numericalConstraints.length} Constraints mit numerischen Suffixen`);
|
||||
|
||||
if (numericalConstraints.length > 0) {
|
||||
for (const constraint of numericalConstraints) {
|
||||
try {
|
||||
await sequelize.query(`
|
||||
ALTER TABLE ${constraint.table_schema}.${constraint.table_name}
|
||||
DROP CONSTRAINT IF EXISTS "${constraint.constraint_name}"
|
||||
`);
|
||||
console.log(` ✅ Entfernt: ${constraint.table_schema}.${constraint.table_name}.${constraint.constraint_name}`);
|
||||
} catch (error) {
|
||||
console.log(` ⚠️ Konnte nicht entfernen: ${constraint.constraint_name} - ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(`⚠️ Konnte numerische Suffix-Constraints nicht entfernen: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Führe das Skript aus, wenn es direkt aufgerufen wird
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
cleanupDatabaseConstraints()
|
||||
|
||||
Reference in New Issue
Block a user