Implement migration to make church_application supervisor_id nullable: Enhance functionality by allowing supervisor_id to be null, improving flexibility in application processing. Add logging for migration success and error handling.
This commit is contained in:
@@ -408,6 +408,32 @@ const syncDatabase = async () => {
|
||||
console.warn('⚠️ Konnte Vocab-Trainer Tabellen nicht sicherstellen:', e?.message || e);
|
||||
}
|
||||
|
||||
// Migration: ChurchApplication supervisor_id nullable machen (kritisch für Funktionalität)
|
||||
console.log("Making church_application supervisor_id nullable...");
|
||||
try {
|
||||
await sequelize.query(`
|
||||
DO $$
|
||||
BEGIN
|
||||
-- Prüfe ob supervisor_id NOT NULL Constraint existiert
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'falukant_data'
|
||||
AND table_name = 'church_application'
|
||||
AND column_name = 'supervisor_id'
|
||||
AND is_nullable = 'NO'
|
||||
) THEN
|
||||
ALTER TABLE falukant_data.church_application
|
||||
ALTER COLUMN supervisor_id DROP NOT NULL;
|
||||
RAISE NOTICE 'supervisor_id NOT NULL Constraint entfernt';
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
`);
|
||||
console.log("✅ church_application supervisor_id ist jetzt nullable");
|
||||
} catch (e) {
|
||||
console.warn('⚠️ Konnte church_application supervisor_id nicht nullable machen:', e?.message || e);
|
||||
}
|
||||
|
||||
// Relationship-/Marriage-Proposal-Änderungen loggen (keine Einträge löschen; ohne db:migrate)
|
||||
console.log("Ensuring relationship change log (falukant) exists...");
|
||||
try {
|
||||
@@ -731,6 +757,32 @@ const syncDatabaseForDeployment = async () => {
|
||||
console.warn('⚠️ Konnte Transport-Spalten nicht nullable machen:', e?.message || e);
|
||||
}
|
||||
|
||||
// Migration: ChurchApplication supervisor_id nullable machen
|
||||
console.log("Making church_application supervisor_id nullable...");
|
||||
try {
|
||||
await sequelize.query(`
|
||||
DO $$
|
||||
BEGIN
|
||||
-- Prüfe ob supervisor_id NOT NULL Constraint existiert
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'falukant_data'
|
||||
AND table_name = 'church_application'
|
||||
AND column_name = 'supervisor_id'
|
||||
AND is_nullable = 'NO'
|
||||
) THEN
|
||||
ALTER TABLE falukant_data.church_application
|
||||
ALTER COLUMN supervisor_id DROP NOT NULL;
|
||||
RAISE NOTICE 'supervisor_id NOT NULL Constraint entfernt';
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
`);
|
||||
console.log("✅ church_application supervisor_id ist jetzt nullable");
|
||||
} catch (e) {
|
||||
console.warn('⚠️ Konnte church_application supervisor_id nicht nullable machen:', e?.message || e);
|
||||
}
|
||||
|
||||
// Cleanup: Entferne verwaiste Einträge vor Schema-Updates
|
||||
console.log("Cleaning up orphaned entries...");
|
||||
try {
|
||||
@@ -882,9 +934,9 @@ const syncDatabaseForDeployment = async () => {
|
||||
SELECT id FROM falukant_type.church_office_type
|
||||
) OR region_id NOT IN (
|
||||
SELECT id FROM falukant_data.region
|
||||
) OR supervisor_id NOT IN (
|
||||
) OR (supervisor_id IS NOT NULL AND supervisor_id NOT IN (
|
||||
SELECT id FROM falukant_data.character
|
||||
);
|
||||
));
|
||||
`, 30000, 'church_application cleanup');
|
||||
const deletedCount12 = result12[1] || 0;
|
||||
if (deletedCount12 > 0) {
|
||||
|
||||
Reference in New Issue
Block a user