-- Migration 057: issue_statusmeldungen table

CREATE TABLE IF NOT EXISTS issue_statusmeldungen (
  id           SERIAL PRIMARY KEY,
  titel        VARCHAR(255) NOT NULL,
  inhalt       TEXT,
  schwere      VARCHAR(20) NOT NULL DEFAULT 'info',
  aktiv        BOOLEAN NOT NULL DEFAULT true,
  erstellt_von UUID REFERENCES users(id),
  created_at   TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at   TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE OR REPLACE FUNCTION update_issue_statusmeldungen_updated_at()
RETURNS TRIGGER AS $$
BEGIN
  NEW.updated_at = NOW();
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trg_issue_statusmeldungen_updated_at
  BEFORE UPDATE ON issue_statusmeldungen
  FOR EACH ROW EXECUTE FUNCTION update_issue_statusmeldungen_updated_at();
