Repository navigation
feat: add Postgres with Drizzle template - #362
Conversation
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.
77e87ff to
f949657
Compare
|
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.
b0b5203 to
e9203df
Compare
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.
|
@greptileai review |
🟢 Tier S · Ready to mergeAdds 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.
📂 Walkthrough · 7
Merged |
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>
What does this PR do?
Adds
node-typescript/postgres-with-drizzle, a function that serves a todo API on Appwrite Postgres through Drizzle ORM.GET /POST /{ title }GET /:idPATCH /:idtitleorcompletedDELETE /:idsrc/schema.ts, and the generated SQL migrations live indrizzle/.npm run db:migrateand create new ones withnpm run db:generate.DATABASE_URL, the database's connection string.drizzle-kitpulls in anesbuildversion with a moderate advisory through@esbuild-kit/core-utils, which failsnpm audit. An npmoverridemoves 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:
todostable.npm run db:migratecreatedtodosand Drizzle's migrations table. A second run changed nothing.completed, an empty update, a missing todo, and an unsupported method./0x1,/1e0,/1.0,/0,/-1,/2147483648,/abcand/1/extra.npm ci --ignore-scripts,npm run build,npm audit(0 vulnerabilities) andprettier --checkpass.drizzle-kit generatereports no schema drift.The
npmaudit job fails on six existing templates that this PR doesn't change:email-contact-form,generate-pdf,password-expiry,payments-with-stripe,subscriptions-with-stripeandsync-with-pinecone.Related PRs and Issues
None.
Have you read the Contributing Guidelines on issues?
Yes.