-- Журнал отключений (вода, свет и т.д.) по домам
CREATE TABLE IF NOT EXISTS outages (
  id             BIGSERIAL PRIMARY KEY,
  building_id    VARCHAR(50) NOT NULL REFERENCES buildings(id) ON DELETE CASCADE,
  start_at       TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  end_at         TIMESTAMPTZ,
  type           VARCHAR(50),
  description    TEXT,
  active         BOOLEAN NOT NULL DEFAULT true,
  created_at     TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at     TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_outages_building ON outages(building_id);
CREATE INDEX IF NOT EXISTS idx_outages_active ON outages(active);
CREATE INDEX IF NOT EXISTS idx_outages_start_at ON outages(start_at);
