@kiwa-lab/migration
v2.1.0
Published
DB migration mock harness for kiwa — Prisma / Drizzle / Kysely / Knex を統一 interface で invoke する in-process mock。 runUp / runDown / applyPendingMigrations / diffSchema / listAppliedMigrations までを real migration lib と同じ signature で叩ける test infra。
Maintainers
Readme
@kiwa-lab/migration
DB migration mock harness for kiwa — Prisma / Drizzle / Kysely / Knex を統一 interface で in-process から叩ける test infra。
Installation
pnpm add -D @kiwa-lab/migration
# or
npm install -D @kiwa-lab/migration
# or
yarn add -D @kiwa-lab/migrationSupported providers
| Provider | Status | Migration style | |---|---|---| | Prisma | ✅ Ready | migration_lock + SQL steps | | Drizzle | ✅ Ready | journal + snapshot | | Kysely | ✅ Ready | numeric prefix TS | | Knex | ✅ Ready | up/down JS |
Quick start
import { describe, expect, it } from 'vitest';
import {
createMigrationClient,
runUp,
runDown,
diffSchema,
listAppliedMigrations,
} from '@kiwa-lab/migration';
describe('user table migration', () => {
it('up → down で schema が初期状態に戻る', async () => {
const client = createMigrationClient({ provider: 'prisma' });
const m = { id: '001', up: 'CREATE TABLE users (id INT)', down: 'DROP TABLE users' };
await runUp(client, m);
expect(listAppliedMigrations(client).map((r) => r.id)).toEqual(['001']);
await runDown(client, m);
expect(listAppliedMigrations(client)).toEqual([]);
});
});API reference
createMigrationClient({ provider: MigrationProvider }): MigrationClient— provider 別 mockrunUp(client, migration: Migration): Promise<MigrationResult>— 1 migration 前進runDown(client, migration: Migration): Promise<MigrationResult>— 1 migration 後退applyPendingMigrations(client, pending: Migration[]): Promise<ApplyPendingResult>— 全 pending 順次適用diffSchema(prev: Schema, next: Schema): SchemaDiff— 前後 schema 差分listAppliedMigrations(client): MigrationRecord[]— history 取得
Test integration
vitest + /kiwa-migration skill で real DB 起動なしで schema evolution を verify。
License
UNLICENSED — see github.com/cardene777/kiwa.
