Test CloufFlare D1 migration

https://orm.drizzle.team/docs/migrations
import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';
import * as schema from './schema';

export const connection = mysql.createConnection({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  multipleStatements: true,
});

export const db = drizzle(connection, { schema });

import 'dotenv/config';
import { migrate } from 'drizzle-orm/mysql2/migrator';
import { db, connection } from './db';

// This will run migrations on the database, skipping the ones already applied
await migrate(db, { migrationsFolder: './drizzle' });

// Don't forget to close the connection, otherwise the script will hang
await connection.end();


This is a great example of migrating to a mysql instance that can connect to any local remote instance.
It is complete in Typescript and can be unit tested!

I would like to do the same with D1
I could not find any documentation, is it possible?
Or should I test by substituting a sqlite instance or an in-memory database?
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Was this page helpful?