Part of Blitz's magic is interacting directly with your database with strong TypeScript types, and Prisma provides this out of the box experience. Most
blitz dbcommands are nothing more than proxies to Prisma behavior. Prisma's very detailed docs are the source of truth here, and will be very useful for helping you get up and running with Blitz's built-in database infrastructure.
In the future, Blitz's plugin system will enable other database solutions to hook into some of this core functionality.
blitz db migrate
As detailed in thePrisma docs, this command reads your schema file (located at
db/schema.prisma) and runs migrations to update tables and columns to match what's in your schema file. Lastly, it'll generate your Prisma Client code to enable you to have typesafe access to your database. This command is marked as "experimental" in the Prisma docs so you may find some rough edges here.
blitz db introspect
Sometimes you need to connect to an existing database and your Blitz app will be a new gateway to existing data.
blitz introspectwill query the database defined in your schema and automatically generate a complete
schema.prismafile for you based on the tables and columns present. Lastly, it'll generate your Prisma Client code to enable you to have typesafe access to your database.
blitz db studio
Often during development you need a quick peek into your database, or maybe you want to seed your database with sample data after running
blitz newso you have sample data to work with. This command opens the Prisma Studio UI at http://localhost:5555 to see and change data in your database with a built-in GUI, rather than needing to download your own SQL client to connect to a remote server or a
blitz db reset
This will completely destroy your database and create a new one with fresh migrations. This is useful in development if you or someone else messes up your db or simply want to clean out test data.