fix: comprehensive init-tables.sql for all new tables (todos, security_audits, daily_summaries, task_comments)
All checks were successful
CI/CD / test (push) Successful in 19s
CI/CD / deploy (push) Successful in 1s

This commit is contained in:
2026-01-30 05:06:52 +00:00
parent cbfeb6db70
commit 8407dde30b
2 changed files with 69 additions and 2 deletions

View File

@@ -11,5 +11,5 @@ COPY . .
# Generate migrations and run # Generate migrations and run
EXPOSE 3100 EXPOSE 3100
RUN apt-get update && apt-get install -y postgresql-client && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y postgresql-client && rm -rf /var/lib/apt/lists/*
COPY init-todos.sql /app/init-todos.sql COPY init-tables.sql /app/init-tables.sql
CMD ["sh", "-c", "echo 'Running init SQL...' && psql \"$DATABASE_URL\" -f /app/init-todos.sql 2>&1 && echo 'Init SQL done' && echo 'Running db:push...' && yes | bun run db:push 2>&1; echo 'db:push exit code:' $? && echo 'Starting server...' && bun run start"] CMD ["sh", "-c", "echo 'Running init SQL...' && psql \"$DATABASE_URL\" -f /app/init-tables.sql 2>&1 && echo 'Init SQL done' && echo 'Running db:push...' && yes | bun run db:push 2>&1; echo 'db:push exit code:' $? && echo 'Starting server...' && bun run start"]

67
backend/init-tables.sql Normal file
View File

@@ -0,0 +1,67 @@
-- 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()
);