ALTER TABLE directory_contacts ADD COLUMN anonymized_at TEXT;
ALTER TABLE directory_contacts ADD COLUMN anonymization_reason TEXT;

CREATE TABLE IF NOT EXISTS private_file_access_log (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  user_id INTEGER REFERENCES users(id) ON DELETE SET NULL,
  resource_type TEXT NOT NULL,
  resource_id INTEGER,
  animal_id INTEGER REFERENCES animals(id) ON DELETE SET NULL,
  action TEXT NOT NULL DEFAULT 'view',
  original_name TEXT,
  ip_address TEXT,
  user_agent TEXT,
  accessed_at TEXT NOT NULL DEFAULT(datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_private_access_date ON private_file_access_log(accessed_at DESC);
CREATE INDEX IF NOT EXISTS idx_private_access_resource ON private_file_access_log(resource_type,resource_id);
