diff --git a/backend/internal/db/queries/tablos.sql b/backend/internal/db/queries/tablos.sql new file mode 100644 index 0000000..b2bb6f2 --- /dev/null +++ b/backend/internal/db/queries/tablos.sql @@ -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; diff --git a/backend/migrations/0003_tablos.sql b/backend/migrations/0003_tablos.sql new file mode 100644 index 0000000..fecb47c --- /dev/null +++ b/backend/migrations/0003_tablos.sql @@ -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;