Skip to content

feat(ddl): TRUNCATE TABLE typed builder with full PG grammar - #168

Merged
productdevbook merged 1 commit into
mainfrom
agent-a/truncate-table-builder
May 19, 2026
Merged

feat(ddl): TRUNCATE TABLE typed builder with full PG grammar#168
productdevbook merged 1 commit into
mainfrom
agent-a/truncate-table-builder

Conversation

@productdevbook

Copy link
Copy Markdown
Owner

Summary

  • Adds a first-class truncate(table | tables) factory + db.schema.truncate(...) that surfaces the full PostgreSQL TRUNCATE grammar (ONLY, RESTART IDENTITY / CONTINUE IDENTITY, CASCADE / RESTRICT, comma-separated multi-table list).
  • Refuses cleanly on dialects without the grammar: MySQL / MSSQL accept only the simple TRUNCATE TABLE <name> form (no multi-table, no modifiers — printer points at ALTER TABLE … AUTO_INCREMENT / DBCC CHECKIDENT for the identity-reset case), SQLite refuses outright with a pointer at db.deleteFrom(t).allRows() as the workaround.
  • Keeps the existing single-table db.schema.truncateTable(name) + TruncateTableBuilder working unchanged so no caller breaks.
  • New feature flags TRUNCATE_TABLE (PG/MySQL/MSSQL) and TRUNCATE_PG_OPTIONS (PG only). Recipe section added to docs/recipes.md.

Test plan

  • pnpm fmt && pnpm lint && pnpm typecheck all green
  • pnpm vitest run — 2507 tests pass (41 new in test/ddl/truncate.test.ts)
  • PG simple / multi-table / ONLY / RESTART IDENTITY / CASCADE / all-in-combination emission
  • MySQL + MSSQL refuse every PG-specific modifier
  • SQLite refuses outright with pointer at DELETE FROM
  • PGlite roundtrip: insert rows + TRUNCATE → count = 0
  • PGlite roundtrip: TRUNCATE … RESTART IDENTITY resets sequence
  • PGlite roundtrip: multi-table TRUNCATE empties both
  • Back-compat: existing db.schema.truncateTable(name) tests still pass

🤖 Generated with Claude Code

Adds a first-class TRUNCATE entry point — `truncate(table | tables)` and
`db.schema.truncate(...)` — that exposes the full PostgreSQL grammar
(`ONLY`, `RESTART IDENTITY` / `CONTINUE IDENTITY`, `CASCADE` / `RESTRICT`,
comma-separated multi-table list) while degrading gracefully on MySQL /
MSSQL (simple form only) and SQLite (refused with a pointer at
`db.deleteFrom(t).allRows()`).

The existing `db.schema.truncateTable(name)` factory + `TruncateTableBuilder`
keeps the single-table API working unchanged; the new factory just expands
the grammar surface.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@productdevbook
productdevbook merged commit 6c0cb42 into main May 19, 2026
1 check passed
@productdevbook
productdevbook deleted the agent-a/truncate-table-builder branch May 19, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant