Skip to content

feat: add database storageΒ #3

@perzeuss

Description

@perzeuss

πŸ—„οΈ Migrate Todos to PostgreSQL Database Storage

πŸ“‹ Overview

Currently, todo items are stored in memory using the mock-todos.ts utilities. Update the backend so that all todo operations persist data in a PostgreSQL database instead of memory, making todos available across restarts and multiple users (no authentication needed).

Replace all existing usages of the mock data functions (getTodos, getTodoById, createTodo, updateTodo, toggleTodo, deleteTodo) with equivalent logic that reads/writes to Postgres via a Node.js database client of your choice (e.g., pg, Prisma, etc.).

Note: Authentication is NOT in scope. You may pick any PostgreSQL client/tooling.


🎯 Acceptance Criteria

  • All endpoints in app/api/todos/ and subroutes persist/read todos in a PostgreSQL database (not memory)
  • Database stores at least: id (primary key), text (string), completed (boolean), createdAt, and updatedAt
  • Supports:
    • Listing all todos (GET /api/todos)
    • Creating a new todo (POST /api/todos)
    • Fetching a single todo (GET /api/todos/[id])
    • Editing a todo (PUT /api/todos/[id])
    • Deleting a todo (DELETE /api/todos/[id])
    • Toggling a todo’s completed state (PATCH /api/todos/[id]/toggle)
  • Uses environment variables for database credentials
  • Provides an SQL schema or migration file, and brief setup instructions

πŸ”§ Technical Requirements

  • Use PostgreSQL 17+ (local install or Docker)
  • Use a Node.js database client that supports Postgres (your choice), e.g.:
  • All existing API routes should preserve their current response format and validation logic
  • Error handling must be retained for non-existent IDs and unexpected failures

🚫 Out of Scope

  • Authentication/authorization (all API endpoints remain public)
  • User-specific todo lists or multi-user support
  • Cloud database hosting or deployment
  • Schema migrations beyond the minimum required for todos

πŸ“š Resources


πŸ’‘ Tips

  • Use async/await for DB operations
  • Add seed data if desired, but not required
  • Document your SQL schema & migration steps in a README or a migration file

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions