Switch to EdgeDB
How to change the database provider to EdgeDB.
EdgeDB is an open-source Postgres data layer designed to address major ergonomic SQL and relational schema modeling limitations while improving type safety and performance.
next-forge
uses Neon as the database provider with Prisma as the ORM as well as Clerk for authentication. This guide will provide the steps you need to switch the database provider from Neon to EdgeDB.
For authentication, another guide will be provided to switch to EdgeDB Auth with access policies, social auth providers, and more.
Here’s how to switch from Neon to EdgeDB for your next-forge
project.
1. Create a new EdgeDB database
Create an account at EdgeDB Cloud. Once done, create a new instance (you can use EdgeDB’s free tier). We’ll later connect to it through the EdgeDB CLI.
2. Swap out the required dependencies in @repo/database
Uninstall the existing dependencies…
… and install the new dependencies:
3. Setup EdgeDB in @repo/database
package
In the @repo/database
directory, run:
Replace <org_name>
and <instance_name>
with the EdgeDB’s organization and instance you’ve previously created in the EdgeDB Cloud.
The init
command creates a new subdirectory called dbschema
, which contains everything related to EdgeDB:
This command also links your environment to the EdgeDB Cloud instance, allowing the EdgeDB client libraries to automatically connect to it without any additional configuration.
You can also delete prisma/
directory from the @repo/database
:
4. Update the database connection code
Update the database connection code to use an EdgeDB client:
5. Update the schema file and generate types
Now, you can modify the database schema:
And apply your changes by running:
Once complete, you can also generate a TypeScript query builder and types from your database schema:
These commands introspect the schema of your database and generate code in the dbschema
directory.
6. Update your queries
Now you can update your queries to use the EdgeDB client.
For example, here’s how we can update the page
query in app/(authenticated)/page.tsx
:
7. Replace Prisma Studio with EdgeDB UI
You can also delete the now unused Prisma Studio app located at apps/studio
:
To manage your database and browse your data, you can run:
8. Extract EdgeDB environment variables for deployment
When deploying your app, you need to provide the EDGEDB_SECRET_KEY
and EDGEDB_INSTANCE
environment variables in your app’s cloud provider to connect to your EdgeDB Cloud instance.
You can generate a dedicated secret key for your instance with npx edgedb cloud secretkey create
or via the web UI’s “Secret Keys” pane in your instance dashboard.