-- Contract Files: Dokumente an Vertraegen
CREATE TABLE app_crm.contract_files (
  id               UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  tenant_id        UUID NOT NULL,
  contract_id      UUID NOT NULL REFERENCES app_crm.contracts(id) ON DELETE CASCADE,
  original_name    VARCHAR(500) NOT NULL,
  storage_path     VARCHAR(1000) NOT NULL,
  mime_type        VARCHAR(200) NOT NULL,
  size             INTEGER NOT NULL,
  uploaded_by      UUID NOT NULL,
  created_at       TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX idx_contract_files_contract_id ON app_crm.contract_files(contract_id);

COMMENT ON TABLE app_crm.contract_files IS 'Vertragsdokumente (PDF, Word, Excel)';
