This project has been migrated from using a JSON file (data/docs.json) to using a PostgreSQL database with Prisma ORM.
npm installThis will install:
@prisma/client- Prisma client for database operationsprisma- Prisma CLI for migrations and schema managementpg- PostgreSQL clienttsx- TypeScript execution for migration scripts
-
Create a PostgreSQL database (locally or using a service like Supabase, Railway, etc.)
-
Create a
.envfile in the root directory with your database connection string:
DATABASE_URL="postgresql://user:password@localhost:5432/developers_doc"Replace user, password, localhost, 5432, and developers_doc with your actual database credentials.
Run Prisma to generate the client and push the schema to your database:
# Generate Prisma Client
npm run db:generate
# Push schema to database (creates tables)
npm run db:pushAlternatively, you can use migrations:
npm run db:migrateIf you have existing data in data/docs.json, you can migrate it to the database:
npx tsx scripts/migrate-json-to-db.tsThis script will:
- Read all data from
data/docs.json - Create projects, documents, pages, and sections in the database
- Use
upsertoperations, so it's safe to run multiple times
You can open Prisma Studio to view your data:
npm run db:studioThis will open a web interface at http://localhost:5555 where you can browse your database.
The database has the following structure:
- Project: Contains projects with multiple documents
- Document: Can belong to a project or be standalone ("Your Docs")
- Page: Belongs to a document, contains multiple sections
- Section: Belongs to a page, contains the actual content
All API routes now use the database instead of the JSON file:
POST /api/projects- Create projectPATCH /api/projects/[id]- Update projectDELETE /api/projects/[id]- Delete projectPOST /api/docs- Create documentPATCH /api/docs/[id]- Update documentDELETE /api/docs/[id]- Delete documentPOST /api/docs/[id]/sections- Add page to documentPATCH /api/docs/[id]/pages/[pageId]- Update page content
During development, the database connection is cached globally to prevent connection exhaustion. The Prisma client is automatically instantiated in lib/db.ts.
Make sure to:
- Set
DATABASE_URLenvironment variable in your production environment - Run
npm run db:generateduring build - Run migrations if using
db:migrateinstead ofdb:push
- Verify your
DATABASE_URLis correct - Check that your database server is running
- Ensure your database user has the necessary permissions
- If migration fails, check the error message
- The migration script uses
upsert, so you can safely re-run it - Make sure your database schema matches the Prisma schema
- Run
npm run db:generateafter schema changes - Restart your TypeScript server in your IDE