golib/cmd/sql-migrate/examples/pg-todos/sql/migrations/2026-04-05-005000_add-indexes-and-constraints.up.sql
AJ ONeal de227bcaaf
feat(sql-migrate/examples): add pg-todos embedded migration runner
Example CLI todo app demonstrating sqlmigrate + pgmigrate for running
migrations directly via pgx/v5 instead of shelling out to psql. Uses
embed.FS for migration files, auto-migrates on startup, and includes
full CRUD for todos and folders with sqlc-ready query files.
2026-04-06 00:40:11 -06:00

11 lines
495 B
SQL

-- add-indexes-and-constraints (up)
CREATE INDEX idx_todos_users_user_id ON todos_users(user_id);
CREATE INDEX idx_folders_todos_todo_id ON folders_todos(todo_id);
CREATE INDEX idx_todos_completed_at ON todos(completed_at) WHERE completed_at IS NULL;
ALTER TABLE todos ADD CONSTRAINT chk_todo_status
CHECK (status IN ('pending', 'in_progress', 'done'));
-- leave this as the last line
INSERT INTO _migrations (name, id) VALUES ('2026-04-05-005000_add-indexes-and-constraints', 'e5f6a7b8');