Skip to content

feat: add Postgres with Drizzle template - #362

Open
atharvadeosthale wants to merge 3 commits into
mainfrom
feat/postgres-with-drizzle
Open

atharvadeosthale wants to merge 3 commits into
mainfrom
feat/postgres-with-drizzle

Conversation

@atharvadeosthale

@atharvadeosthale atharvadeosthale commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Adds node-typescript/postgres-with-drizzle, a function that serves a todo API on Appwrite Postgres through Drizzle ORM.

Route Action
GET / List todos
POST / Create a todo from { title }
GET /:id Get a todo
PATCH /:id Update title or completed
DELETE /:id Delete a todo
  • The schema lives in src/schema.ts, and the generated SQL migrations live in drizzle/.
  • The function never changes the schema. Developers apply migrations from their machine with npm run db:migrate and create new ones with npm run db:generate.
  • The only setting is DATABASE_URL, the database's connection string.

drizzle-kit pulls in an esbuild version with a moderate advisory through @esbuild-kit/core-utils, which fails npm audit. An npm override moves that copy to ^0.25.12. Migrations still generate the same SQL.

Test Plan

Deployed as a Node 22 function against an Appwrite Postgres database:

  • Before migrating, the function created no tables, and requests failed on the missing todos table.
  • npm run db:migrate created todos and Drizzle's migrations table. A second run changed nothing.
  • Every route returned the expected response after the migration.
  • Errors return the documented status and message: an empty or 256-character title, invalid JSON, a non-boolean completed, an empty update, a missing todo, and an unsupported method.
  • Invalid IDs return 404 without querying: /0x1, /1e0, /1.0, /0, /-1, /2147483648, /abc and /1/extra.
  • The same routes pass through the pooled connection string (port 6432). 2,000 prepared-statement queries from 20 clients spread across all 10 pooler backends with no failures.
  • On Node 22: npm ci --ignore-scripts, npm run build, npm audit (0 vulnerabilities) and prettier --check pass. drizzle-kit generate reports no schema drift.

The npm audit job fails on six existing templates that this PR doesn't change: email-contact-form, generate-pdf, password-expiry, payments-with-stripe, subscriptions-with-stripe and sync-with-pinecone.

Related PRs and Issues

None.

Have you read the Contributing Guidelines on issues?

Yes.

A Node.js (TypeScript) function that serves a todo API on Appwrite
Postgres through Drizzle ORM. The schema lives in src/schema.ts, and
drizzle-kit generates the SQL migrations in drizzle/. The function applies
pending migrations on its first execution. The only setting is
DATABASE_URL.

drizzle-kit depends on an esbuild version with a moderate advisory
through @esbuild-kit/core-utils, which fails npm audit. An npm override
moves that copy to ^0.25.12; migrations generate the same SQL.
@atharvadeosthale
atharvadeosthale force-pushed the feat/postgres-with-drizzle branch from 77e87ff to f949657 Compare September 25, 2026 06:21
@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Low risk] Adds a new template project for a todo API.

The PR appears safe to merge; no new actionable issue or outstanding previous finding remains.

Summary

The template now applies migrations from a developer’s machine rather than on function startup. It also disables prepared statements for pooled connections and validates todo IDs as decimal integers within the database column’s range.

Reviews (2) · Last reviewed commit: "fix: disable prepared statements for poo..."

Comment thread node-typescript/postgres-with-drizzle/src/db.ts Outdated
Comment thread node-typescript/postgres-with-drizzle/src/db.ts Outdated
Comment thread node-typescript/postgres-with-drizzle/src/main.ts
Comment thread node-typescript/postgres-with-drizzle/package.json Outdated
The function no longer applies migrations when it starts. Developers
apply the SQL in drizzle/ themselves with `npm run db:migrate`, which
avoids concurrent cold starts racing on the same migration and keeps
schema changes out of production requests.

Todo IDs must now be decimal digits within the range of a Postgres
integer. Before, Number() accepted values like `/0x10` as ID 16, and
IDs above 2147483647 caused a database error instead of a 404.
@atharvadeosthale
atharvadeosthale force-pushed the feat/postgres-with-drizzle branch 2 times, most recently from b0b5203 to e9203df Compare September 25, 2026 06:32
Some transaction-mode poolers, such as PgBouncer before 1.21, route consecutive queries to different backends, so a statement prepared on one backend is missing on the next.
@atharvadeosthale

Copy link
Copy Markdown
Member Author

@greptileai review

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