Add SQL init fallback for todos table creation

This commit is contained in:
2026-01-30 04:59:17 +00:00
parent 602e1ed75b
commit fd823e2d75
2 changed files with 24 additions and 1 deletions

View File

@@ -10,4 +10,6 @@ COPY . .
# Generate migrations and run # Generate migrations and run
EXPOSE 3100 EXPOSE 3100
CMD ["sh", "-c", "echo 'Running db:push...' && yes | bun run db:push 2>&1 && echo 'db:push done' && bun run start"] RUN apt-get update && apt-get install -y postgresql-client && rm -rf /var/lib/apt/lists/*
COPY init-todos.sql /app/init-todos.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"]

21
backend/init-todos.sql Normal file
View File

@@ -0,0 +1,21 @@
-- Create todo_priority enum if not exists
DO $$ BEGIN
CREATE TYPE todo_priority AS ENUM ('high', 'medium', 'low', 'none');
EXCEPTION WHEN duplicate_object THEN null;
END $$;
-- Create todos table if not exists
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()
);