Files
hammer-queue/backend/init-tables.sql
Hammer 061618cfab
Some checks failed
CI/CD / test (push) Has been cancelled
CI/CD / deploy (push) Has been cancelled
Security Scan / SAST - Semgrep (push) Has been cancelled
Security Scan / Dependency Scan - Trivy (push) Has been cancelled
Security Scan / Secret Detection - Gitleaks (push) Has been cancelled
feat: comprehensive security audit system - OWASP Top 10, checklist, score history, scan pipeline
Phase 1: OWASP API Top 10 per API with real findings from code inspection
- Hammer Dashboard, Network App, Todo App, nKode all audited against 10 OWASP risks
- Per-API scorecards with visual grid, color-coded by status

Phase 2: Full security checklist
- 9 categories: Auth, Authz, Input Validation, Transport, Rate Limiting, etc
- Interactive checklist UI with click-to-cycle status
- Per-project checklist with progress tracking
- Comprehensive category audits (Auth, Data Protection, Logging, Infrastructure, etc)

Phase 3: Automated pipeline
- Semgrep SAST, Trivy dependency scan, Gitleaks secret detection
- Gitea Actions CI workflow (security-scan.yml)
- Scan results stored in DB and displayed in dashboard

Phase 4: Dashboard polish
- Overall security posture score with weighted calculation
- Score trend charts (SVG) with 7-day history
- Critical findings highlight section
- Score history snapshots API
- Tab-based navigation (Overview, Checklist, per-project)

New DB tables: security_score_history, security_checklist, security_scan_results
Seed data populated from real code review of all repos
2026-01-30 15:16:10 +00:00

119 lines
3.5 KiB
SQL

-- Create all new tables and enums that db:push might miss
-- Idempotent: safe to run multiple times
-- ═══ Enums ═══
DO $$ BEGIN
CREATE TYPE todo_priority AS ENUM ('high', 'medium', 'low', 'none');
EXCEPTION WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
CREATE TYPE security_audit_status AS ENUM ('strong', 'needs_improvement', 'critical');
EXCEPTION WHEN duplicate_object THEN null;
END $$;
-- ═══ Todos ═══
CREATE TABLE IF NOT EXISTS todos (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id TEXT NOT NULL,
title TEXT NOT NULL,
description TEXT,
is_completed BOOLEAN NOT NULL DEFAULT false,
priority todo_priority NOT NULL DEFAULT 'none',
category TEXT,
due_date TIMESTAMPTZ,
completed_at TIMESTAMPTZ,
sort_order INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- ═══ Security Audits ═══
CREATE TABLE IF NOT EXISTS security_audits (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
project_name TEXT NOT NULL,
category TEXT NOT NULL,
findings JSONB DEFAULT '[]'::jsonb,
score INTEGER NOT NULL DEFAULT 0,
last_audited TIMESTAMPTZ NOT NULL DEFAULT now(),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- ═══ Daily Summaries ═══
CREATE TABLE IF NOT EXISTS daily_summaries (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
date TEXT NOT NULL UNIQUE,
content TEXT NOT NULL,
highlights JSONB DEFAULT '[]'::jsonb,
stats JSONB DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- ═══ Task Comments (if not already created) ═══
CREATE TABLE IF NOT EXISTS task_comments (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
task_id UUID NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
author_id TEXT,
author_name TEXT NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- ═══ Security Score History ═══
CREATE TABLE IF NOT EXISTS security_score_history (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
project_name TEXT NOT NULL,
score INTEGER NOT NULL,
total_findings INTEGER NOT NULL DEFAULT 0,
critical_count INTEGER NOT NULL DEFAULT 0,
warning_count INTEGER NOT NULL DEFAULT 0,
strong_count INTEGER NOT NULL DEFAULT 0,
recorded_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- ═══ Security Checklist ═══
DO $$ BEGIN
CREATE TYPE security_checklist_status AS ENUM ('pass', 'fail', 'partial', 'not_applicable', 'not_checked');
EXCEPTION WHEN duplicate_object THEN null;
END $$;
CREATE TABLE IF NOT EXISTS security_checklist (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
project_name TEXT NOT NULL,
checklist_category TEXT NOT NULL,
item TEXT NOT NULL,
status security_checklist_status NOT NULL DEFAULT 'not_checked',
notes TEXT,
checked_by TEXT,
checked_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- ═══ Security Scan Results ═══
CREATE TABLE IF NOT EXISTS security_scan_results (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
project_name TEXT NOT NULL,
scan_type TEXT NOT NULL,
scan_status TEXT NOT NULL DEFAULT 'pending',
findings JSONB DEFAULT '[]'::jsonb,
summary JSONB DEFAULT '{}'::jsonb,
triggered_by TEXT,
commit_sha TEXT,
branch TEXT,
duration INTEGER,
started_at TIMESTAMPTZ,
completed_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);