feat(03-01): add tablos migration and sqlc queries
- 0003_tablos.sql: tablos table with user_id FK + ON DELETE CASCADE + tablos_user_id_idx - tablos.sql: 5 named queries (ListTablosByUser, GetTabloByID, InsertTablo, UpdateTablo, DeleteTablo) - UpdateTablo sets updated_at = now() explicitly (Pitfall 7) - color not editable in UpdateTablo per Phase 3 scope - sqlc generates Tablo struct with pgtype.Text for description/color (not committed per .gitignore convention)
This commit is contained in:
parent
f53b54637b
commit
f1b8d6e629
2 changed files with 42 additions and 0 deletions
24
backend/internal/db/queries/tablos.sql
Normal file
24
backend/internal/db/queries/tablos.sql
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
-- name: ListTablosByUser :many
|
||||
SELECT id, user_id, title, description, color, created_at, updated_at
|
||||
FROM tablos
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: GetTabloByID :one
|
||||
SELECT id, user_id, title, description, color, created_at, updated_at
|
||||
FROM tablos
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: InsertTablo :one
|
||||
INSERT INTO tablos (user_id, title, description, color)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, user_id, title, description, color, created_at, updated_at;
|
||||
|
||||
-- name: UpdateTablo :one
|
||||
UPDATE tablos
|
||||
SET title = $2, description = $3, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, user_id, title, description, color, created_at, updated_at;
|
||||
|
||||
-- name: DeleteTablo :exec
|
||||
DELETE FROM tablos WHERE id = $1;
|
||||
18
backend/migrations/0003_tablos.sql
Normal file
18
backend/migrations/0003_tablos.sql
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
-- migrations/0003_tablos.sql
|
||||
-- Phase 3: Tablos CRUD
|
||||
|
||||
-- +goose Up
|
||||
CREATE TABLE tablos (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
title text NOT NULL,
|
||||
description text,
|
||||
color text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX tablos_user_id_idx ON tablos(user_id);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE IF EXISTS tablos;
|
||||
Loading…
Reference in a new issue