-- Reverse of 020. Idempotent (mirrors the up-migration's defensive style).

DO $$ BEGIN ALTER TABLE paliad.projects           RENAME TO projekte;            EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.project_teams      RENAME TO projekt_teams;       EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.project_events     RENAME TO projekt_events;      EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.deadlines          RENAME TO fristen;             EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.appointments       RENAME TO termine;             EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.parties            RENAME TO parteien;            EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.notes              RENAME TO notizen;             EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.departments        RENAME TO dezernate;           EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.department_members RENAME TO dezernat_mitglieder; EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.documents          RENAME TO dokumente;           EXCEPTION WHEN undefined_table THEN NULL; END $$;

DO $$ BEGIN ALTER FUNCTION paliad.can_see_project(uuid) RENAME TO can_see_projekt; EXCEPTION WHEN undefined_function THEN NULL; END $$;
DO $$ BEGIN ALTER FUNCTION paliad.note_is_visible(uuid, uuid, uuid, uuid) RENAME TO notiz_is_visible; EXCEPTION WHEN undefined_function THEN NULL; END $$;

DO $$ BEGIN ALTER TABLE paliad.deadlines           RENAME COLUMN project_id TO projekt_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.appointments        RENAME COLUMN project_id TO projekt_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.parties             RENAME COLUMN project_id TO projekt_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.notes               RENAME COLUMN project_id TO projekt_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.documents           RENAME COLUMN project_id TO projekt_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.project_events      RENAME COLUMN project_id TO projekt_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.checklist_instances RENAME COLUMN project_id TO projekt_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.project_teams       RENAME COLUMN project_id TO projekt_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;

DO $$ BEGIN ALTER TABLE paliad.reminder_log RENAME COLUMN deadline_id      TO frist_id;       EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.appointments RENAME COLUMN appointment_type TO termin_type;    EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.notes        RENAME COLUMN deadline_id      TO frist_id;       EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.notes        RENAME COLUMN appointment_id   TO termin_id;      EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.notes        RENAME COLUMN project_event_id TO akten_event_id; EXCEPTION WHEN undefined_column OR undefined_table THEN NULL; END $$;

DO $$ BEGIN ALTER TABLE paliad.checklist_feedback RENAME TO checklisten_feedback; EXCEPTION WHEN undefined_table THEN NULL; END $$;
DO $$ BEGIN ALTER TABLE paliad.court_feedback     RENAME TO gerichte_feedback;    EXCEPTION WHEN undefined_table THEN NULL; END $$;
