We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Automatic Migrations

So we can generate migrations based on our schema, and we can use these migrations to update our database. Doing this manually is fine for now, but as our project grows, we'll want to automate this process.

To configure automatic migrations:

  1. import type { MigrationConfig } from "drizzle-orm/migrator";
    
    const migrationConfig: MigrationConfig = {
      migrationsFolder: "./src/db/migrations",
    };
    
  2. import postgres from "postgres";
    import { migrate } from "drizzle-orm/postgres-js/migrator";
    import { drizzle } from "drizzle-orm/postgres-js";
    
    const migrationClient = postgres(config.db.url, { max: 1 });
    await migrate(drizzle(migrationClient), config.db.migrationConfig);
    

Run and submit the CLI tests.