Skip to content

feat: add Postgres with Drizzle template - #362

Merged
atharvadeosthale merged 5 commits into
mainfrom
feat/postgres-with-drizzle
Oct 13, 2026
Merged

atharvadeosthale merged 5 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

@hansi-codes

hansi-codes Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Adds a Node.js TypeScript todo API backed by Appwrite Postgres and Drizzle ORM, with routes for listing, creating, reading, updating, and deleting todos. Includes the Drizzle schema and initial migration, local migration commands, database connection setup, and usage documentation.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 7
File Change
node-typescript/postgres-with-drizzle/src/main.ts, node-typescript/postgres-with-drizzle/src/utils.ts Implement todo routes and validate request bodies, titles, and IDs.
node-typescript/postgres-with-drizzle/src/db.ts, node-typescript/postgres-with-drizzle/src/schema.ts Set up the reusable Postgres/Drizzle connection and todo table schema.
node-typescript/postgres-with-drizzle/drizzle/ Add the initial todos SQL migration and Drizzle migration metadata.
node-typescript/postgres-with-drizzle/package.json, node-typescript/postgres-with-drizzle/package-lock.json Add ORM, Postgres, migration, build, and formatting dependencies and scripts.
node-typescript/postgres-with-drizzle/drizzle.config.ts, node-typescript/postgres-with-drizzle/tsconfig.json, node-typescript/postgres-with-drizzle/env.d.ts Configure Drizzle migrations, TypeScript compilation, and DATABASE_URL typing.
node-typescript/postgres-with-drizzle/README.md Document routes, migration workflow, deployment settings, and database configuration.
node-typescript/postgres-with-drizzle/.gitignore, node-typescript/postgres-with-drizzle/.prettierrc.json Add project ignore rules and Prettier settings.

Merged main (a1f7e7f); no changes to this PR's code since 6925b92 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@atharvadeosthale
atharvadeosthale merged commit fac94aa into main Oct 13, 2026
28 checks passed
@atharvadeosthale
atharvadeosthale deleted the feat/postgres-with-drizzle branch October 13, 2026 06:00
NancyWei123 pushed a commit to NancyWei123/appwrite that referenced this pull request Oct 19, 2026
Registers three Node function templates from appwrite/templates:

- node-typescript/postgres-with-drizzle (appwrite/templates#362), a todo
  API on Appwrite Postgres through Drizzle ORM. It builds with tsc and
  runs dist/main.js.
- node/payments-with-dodo-payments and
  node/subscriptions-with-dodo-payments (appwrite/templates#366), which
  follow the Lemon Squeezy pair.

The entries point at templates 1.4.0, the first tag that will contain
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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