Skip to Content

Database

  • When running bun dev, the db:studio is automatically run in parallel so you can easily access the development database at https://local.drizzle.studio.
💡
Tip

If when you access https://local.drizzle.studio it keeps loading, disable your browser’s protections, such as Brave’s Shields or Ad Blockers.

Drizzle

To define new tables/schemas, create a new .ts file in the src/server/db/schema, following the existing pattern there.

Then, add the new table to the schema object in the src/server/db/db.ts file. Follow the existing pattern.

To change the user table, see the additionalFields in the src/server/auth.ts. There it’s explained how to do it, as we use BetterAuth.

  • After doing any of the above, run bun db:generate and then bun db:migrate to restart the local server.

Production Migration

The last item from the previous section informs how to update the local database. For the production database, there is nothing to be done!

By NextStack’s default, the build script in the package.json also runs the db:migrate command. This means that when you push your commit and Vercel builds the project, the database will then be automatically migrated if the build is successful, and if the migration fails, so will fail the deployment.

Neon

Last updated on