Releases: kysely-org/kysely-knex
Releases · kysely-org/kysely-knex
v0.2.0
Hey 👋
This release comes with the KyselyFsMigrationSource
custom migration source. It passes a Kysely instance as the 2nd argument to all your Knex-managed migrations, allowing you to run start using Kysely in migrations from a certain point in time, and also slowly migrate existing migrations to use Kysely.
migrations/20240101000000_add_email_column.ts
:
import type {Knex} from 'knex'
import type {Kysely} from 'kysely'
export async function up(_: Knex, kysely: Kysely<any>): Promise<void> {
await kysely.schema
.alterTable('dog_walker')
.addColumn('email', 'varchar', (cb) => cb.unique())
.execute()
}
export async function down(_: Knex, kysely: Kysely<any>): Promise<void> {
await kysely.schema.alterTable('dog_walker').dropColumn('email').execute()
}
Pass the migration source to all migrate commands as follows:
scripts/migrate-to-latest.ts
:
import {join} from 'node:path'
import {KyselyFsMigrationSource} from 'kysely-knex'
import {knex} from '../src/knex'
import {kysely} from '../src/kysely'
export const migrationSource = new KyselyFsMigrationSource({
kyselySubDialect: new PGColdDialect(),
migrationDirectories: join(__dirname, '../migrations'),
})
await knex.migrate.latest({migrationSource})
or pass it to Knex CLI globally:
knexfile.ts
:
const {KyselyFsMigrationSource, PGColdDialect} = require('kysely-knex')
module.exports = {
// ...
migrations: {
// ...
migrationSource: new KyselyFsMigrationSource({
kyselySubDialect: new PGColdDialect(),
migrationDirectories: 'migrations',
}),
// ...
},
// ...
}