Module

x/kysely_postgrs_js_dialect/deps.ts>kysely.Migrator#migrateToLatest

Kysely dialect for PostgreSQL using the Postgres.js client.
method kysely.Migrator.prototype.migrateToLatest
import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.3/deps.ts";
const { Migrator } = kysely;

Runs all migrations that have not yet been run.

This method returns a MigrationResultSet instance and never throws. {@link MigrationResultSet.error} holds the error if something went wrong. {@link MigrationResultSet.results} contains information about which migrations were executed and which failed. See the examples below.

This method goes through all possible migrations provided by the provider and runs the ones whose names come alphabetically after the last migration that has been run. If the list of executed migrations doesn't match the beginning of the list of possible migrations an error is returned.

Examples

const db = new Kysely<Database>({
  dialect: new PostgresDialect({
    host: 'localhost',
    database: 'kysely_test',
  }),
})

const migrator = new Migrator({
  db,
  provider: new FileMigrationProvider(
    // Path to the folder that contains all your migrations.
    'some/path/to/migrations'
  )
})

const { error, results } = await migrator.migrateToLatest()

results?.forEach((it) => {
  if (it.status === 'Success') {
    console.log(`migration "${it.migrationName}" was executed successfully`)
  } else if (it.status === 'Error') {
    console.error(`failed to execute migration "${it.migrationName}"`)
  }
})

if (error) {
  console.error('failed to run `migrateToLatest`')
  console.error(error)
}