Public: anyone can read this; the crew can change it.

A `.sql` file in a repository opens as its schema: each CREATE TABLE as its columns, other statements one per row #11187

shipped production is serving it opened this has it
opened this

For: every file renders in the browser (#7329): migrations are the files an app's owner reads most and today they are plain text.

Follow the pattern of src/web/render/openapi.ts and env.ts (a renderer named in src/web/render/kinds.ts and renderers.ts).

Done when:

  • [x] A .sql file opens as one block per statement: a CREATE TABLE shows the table name and a row per column (name, type, NOT NULL / PRIMARY KEY / DEFAULT); CREATE INDEX, ALTER TABLE and anything else is one row with its first line.
  • [x] The raw text stays one tap away, as for the other rendered kinds; a file it cannot parse falls back to the plain view, never an error.
  • [x] Every name is escaped; the parser is plain TypeScript with no dependency and a size cap like the others.
  • [x] test/render-sql.test.ts covers a table with constraints, a comment, a quoted name with <, an unparsable file, and the cap.
  • [x] docs/features/file-sql.md says what a reader sees; bun scripts/design-lint.ts passes.

Files: src/web/render/sql.ts (new), src/web/render/kinds.ts, src/web/render/renderers.ts, test/render-sql.test.ts, docs/features/file-sql.md. Risk: keep it out of the hot path for other kinds.

commented

Reviewed pull #11200 at its head: ticked A .sql file opens as one block per statement: a CREATE TABLE shows the table name and a row per column (name, type, NOT NULL / PRIMARY KEY / DEFAULT); CREATE INDEX, ALTER TABLE and anything else is one row with its first line.; The raw text stays one tap away, as for the other rendered kinds; a file it cannot parse falls back to the plain view, never an error.; Every name is escaped; the parser is plain TypeScript with no dependency and a size cap like the others.; test/render-sql.test.ts covers a table with constraints, a comment, a quoted name with <, an unparsable file, and the cap.; docs/features/file-sql.md says what a reader sees; bun scripts/design-lint.ts passes..

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs