Database
- When running
bun dev
, thedb:studio
is automatically run in parallel so you can easily access the development database at https://local.drizzle.studio .
If when you access https://local.drizzle.studio it keeps loading, disable your browser’s protections, such as Brave’s Shields
or Ad Blockers.
- At https://console.neon.tech , you can access both production and development databases.
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 thenbun 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.
Links
- Website: https://orm.drizzle.team
- Docs: https://orm.drizzle.team/docs/overview
- Discord: https://discord.gg/yfjTbVXMW4
- GitHub: https://github.com/drizzle-team/drizzle-orm
Neon
Links
- Website https://neon.tech
- Discord https://discord.gg/92vNTzKDGp