1. 21
    Implement Drizzle ORM for Development and Deploy to a Fly.io Volume
    15m 31s

Implement Drizzle ORM for Development and Deploy to a Fly.io Volume

InstructorLazar Nikolov

Share this video with your friends

Send Tweet

Drizzle ORM is a library that allows us to connect, define, and interact with any kind of database.

To set it up, we will need to install its packages and then instantiate it in its own file.

We will just need a single table that will keep track of the article slug and the number of likes for that article. We can define this shape in src/db/schema.ts to create a likes table.

Then, we will define an npm script in package.json that will generate the migration files for us, which we will apply when we first use the db instance after deployment. We'll also create a script to run the Drizzle studio app that will be useful in the future.

Drizzle will also have its own config file at the root of the project in which we will define the schema, the migrations location, the driver, etc. To prepare it for production, we will need to create a volume in fly.io and mount it to our app.

This way when our blog gets deployed, production will reference the volume in fly.io and development will reference a local.db file.