Migrate blog data layer from Xata to Drizzle + Postgres (Railway)#3
Migrate blog data layer from Xata to Drizzle + Postgres (Railway)#3Sam-Apostel wants to merge 5 commits into
Conversation
Replaces the deleted Xata workspace with Drizzle ORM over a Postgres database (intended for Railway). Adds schema, db client, drizzle-kit config and a seed script; rewrites every Xata query (home, article, project, project metadata, rss) to Drizzle. DB-backed routes are now rendered dynamically so the build no longer needs DB access.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Summary
|
The two dedicated pages were missed in the first pass: - app/a/communication-between-components used the removed getXataClient (this broke the build); now queries Drizzle. - app/p/polar-printer's generateMetadata hits the DB; mark both routes force-dynamic so the build doesn't need a database.
Next imports every route module during build; throwing at import time when DATABASE_URL is unset failed the build on environments without a DB. Defer client creation to first query via a proxy, so `next build` (all DB routes are force-dynamic) succeeds without a database and only runtime queries require the connection.
Why
The blog read from a Xata database (
controll-room) that has been deleted, which broke every page — the homepage queriedxata.db.projectand threw. This moves the data layer to Drizzle ORM over Postgres, intended to run on Railway alongside the other services.What changed
globals/xata.ts(generated client) and.xatarc.globals/schema.ts— Drizzle schema for the two tables the blog actually uses (blogpost,project). The other Xata tables (feed,mail,thread,contact,update) belonged to other apps and were intentionally left out.globals/db.tsnow exports a Drizzledb(postgres-js driver) +Blogpost/Projectrow types, so existing component imports keep working.app/page.tsx,app/a/[slug]/page.tsx,app/p/[slug]/page.tsx,app/p/generateProjectMetadata.ts,app/rss.xml/route.tsx.dynamic = 'force-dynamic'with nogenerateStaticParams, sonext buildno longer needs a reachable database (Railway's private DB host isn't reachable at build). The MDX dedicated pages (/a/communication-between-components,/p/polar-printer) are unaffected.package.json: dropped@xata.io/*, addeddrizzle-orm,postgres,drizzle-kit,tsx; addeddb:push/db:generate/db:migrate/db:seed/db:studioscripts.scripts/seed.ts+seed/README.mdto load your Xata JSON exports, andMIGRATION.mdwith the full runbook..env.distnow documentsDATABASE_URL.Remaining manual steps (need your input / Railway access)
DATABASE_URL.DATABASE_URL=… npm run db:pushto create the schema.blogpost.json/project.jsonexports into./seed/andnpm run db:seed(adjust field mapping inscripts/seed.tsif your export shape differs).DATABASE_URLas a service variable; pointsams.landat it and retire the Vercel project.Not yet verified
I couldn't run
npm install/next buildin this environment — dependency version ranges (drizzle-orm^0.38,drizzle-kit^0.30,postgres^3.4,tsx^4.19) and the build should be confirmed locally. Logic is a 1:1 port of the previous Xata filters (incl.published < nowexcluding drafts, projects ordered byupdated_at).https://claude.ai/code/session_01FgRm4bvPixcxQoyZu4X8Gh
Generated by Claude Code