Skip to content

Commit b751905

Browse files
authored
feat: expose migrations from 'kysely/migration'. deprecate migration exports in root. (#1618)
* ... ... .. * ... * ... * ... * ...
1 parent 11d600c commit b751905

9 files changed

Lines changed: 116 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
dist
22
/helpers
3+
migration.*
34
/test/browser/bundle.js
45
node_modules
56
.vscode

deno.check.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"kysely/helpers/mysql": "./dist/esm/helpers/mysql.js",
1212
"kysely/helpers/postgres": "./dist/esm/helpers/postgres.js",
1313
"kysely/helpers/sqlite": "./dist/esm/helpers/sqlite.js",
14+
"kysely/migration": "./dist/esm/migration",
1415
"lodash/snakeCase": "npm:lodash/snakeCase",
1516
"mysql2": "npm:mysql2",
1617
"pg": "npm:pg",

jsr.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"./helpers/mysql": "./src/helpers/mysql.ts",
99
"./helpers/mssql": "./src/helpers/mssql.ts",
1010
"./helpers/postgres": "./src/helpers/postgres.ts",
11-
"./helpers/sqlite": "./src/helpers/sqlite.ts"
11+
"./helpers/sqlite": "./src/helpers/sqlite.ts",
12+
"./migration": "./src/migration/index.ts"
1213
},
1314
"publish": {
1415
"include": [

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"files": [
4040
"dist",
4141
"helpers",
42+
"migration.d.ts",
43+
"migration.js",
4244
"outdated-typescript.d.ts"
4345
],
4446
"exports": {
@@ -66,6 +68,11 @@
6668
"import": "./dist/esm/helpers/sqlite.js",
6769
"require": "./dist/cjs/helpers/sqlite.js",
6870
"default": "./dist/cjs/helpers/sqlite.js"
71+
},
72+
"./migration": {
73+
"import": "./dist/esm/migration/index.js",
74+
"require": "./dist/cjs/migration/index.js",
75+
"default": "./dist/cjs/migration/index.js"
6976
}
7077
},
7178
"scripts": {

site/docs/migrations.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ There is also an `allowUnorderedMigrations` option. This option will allow new m
3737
To allow unordered migrations, pass the `allowUnorderedMigrations` option to Migrator:
3838

3939
```ts
40+
import { FileMigrationProvider, Migrator } from 'kysely/migration'
41+
4042
const migrator = new Migrator({
4143
db,
4244
provider: new FileMigrationProvider(...),
@@ -140,6 +142,8 @@ For more information, visit https://github.com/kysely-org/kysely-ctl.
140142
You can then use:
141143

142144
```ts
145+
import { Migrator } from 'kysely/migration'
146+
143147
const migrator = new Migrator(migratorConfig)
144148
await migrator.migrateToLatest()
145149
```
@@ -152,12 +156,8 @@ You will probably want to add a simple migration script to your projects like th
152156
import * as path from 'path'
153157
import { Pool } from 'pg'
154158
import { promises as fs } from 'fs'
155-
import {
156-
Kysely,
157-
Migrator,
158-
PostgresDialect,
159-
FileMigrationProvider,
160-
} from 'kysely'
159+
import { Kysely, PostgresDialect } from 'kysely'
160+
import { FileMigrationProvider, Migrator } from 'kysely/migration'
161161
import { Database } from './types'
162162

163163
async function migrateToLatest() {

src/index.ts

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { KyselyTypeError } from './util/type-error.js'
2+
13
export * from './kysely.js'
24
export * from './query-creator.js'
35

@@ -111,9 +113,6 @@ export * from './dialect/pglite/pglite-dialect-config.js'
111113
export * from './query-compiler/default-query-compiler.js'
112114
export * from './query-compiler/query-compiler.js'
113115

114-
export * from './migration/migrator.js'
115-
export * from './migration/file-migration-provider.js'
116-
117116
export * from './plugin/kysely-plugin.js'
118117
export * from './plugin/camel-case/camel-case-plugin.js'
119118
export * from './plugin/deduplicate-joins/deduplicate-joins-plugin.js'
@@ -315,3 +314,89 @@ export type {
315314
RecursiveCommonTableExpression,
316315
QueryCreatorWithCommonTableExpression,
317316
} from './parser/with-parser.js'
317+
318+
// deprecated exports
319+
320+
/**
321+
* @deprecated import from 'kysely/migration' instead.
322+
*/
323+
export declare const DEFAULT_ALLOW_UNORDERED_MIGRATIONS: KyselyTypeError<"import from 'kysely/migration' instead">
324+
/**
325+
* @deprecated import from 'kysely/migration' instead.
326+
*/
327+
export declare const DEFAULT_MIGRATION_LOCK_TABLE: KyselyTypeError<"import from 'kysely/migration' instead">
328+
/**
329+
* @deprecated import from 'kysely/migration' instead.
330+
*/
331+
export declare const DEFAULT_MIGRATION_TABLE: KyselyTypeError<"import from 'kysely/migration' instead">
332+
/**
333+
* @deprecated import from 'kysely/migration' instead.
334+
*/
335+
export declare const MIGRATION_LOCK_ID: KyselyTypeError<"import from 'kysely/migration' instead">
336+
/**
337+
* @deprecated import from 'kysely/migration' instead.
338+
*/
339+
export type MigrateOptions =
340+
KyselyTypeError<"import from 'kysely/migration' instead">
341+
/**
342+
* @deprecated import from 'kysely/migration' instead.
343+
*/
344+
export type Migration =
345+
KyselyTypeError<"import from 'kysely/migration' instead">
346+
/**
347+
* @deprecated import from 'kysely/migration' instead.
348+
*/
349+
export type MigrationInfo =
350+
KyselyTypeError<"import from 'kysely/migration' instead">
351+
/**
352+
* @deprecated import from 'kysely/migration' instead.
353+
*/
354+
export type MigrationProvider =
355+
KyselyTypeError<"import from 'kysely/migration' instead">
356+
/**
357+
* @deprecated import from 'kysely/migration' instead.
358+
*/
359+
export type MigrationResult =
360+
KyselyTypeError<"import from 'kysely/migration' instead">
361+
/**
362+
* @deprecated import from 'kysely/migration' instead.
363+
*/
364+
export type MigrationResultSet =
365+
KyselyTypeError<"import from 'kysely/migration' instead">
366+
/**
367+
* @deprecated import from 'kysely/migration' instead.
368+
*/
369+
export declare const Migrator: KyselyTypeError<"import from 'kysely/migration' instead">
370+
/**
371+
* @deprecated import from 'kysely/migration' instead.
372+
*/
373+
export type MigratorProps =
374+
KyselyTypeError<"import from 'kysely/migration' instead">
375+
/**
376+
* @deprecated import from 'kysely/migration' instead.
377+
*/
378+
export declare const NO_MIGRATIONS: KyselyTypeError<"import from 'kysely/migration' instead">
379+
/**
380+
* @deprecated import from 'kysely/migration' instead.
381+
*/
382+
export type NoMigrations =
383+
KyselyTypeError<"import from 'kysely/migration' instead">
384+
/**
385+
* @deprecated import from 'kysely/migration' instead.
386+
*/
387+
export declare const FileMigrationProvider: KyselyTypeError<"import from 'kysely/migration' instead">
388+
/**
389+
* @deprecated import from 'kysely/migration' instead.
390+
*/
391+
export type FileMigrationProviderFS =
392+
KyselyTypeError<"import from 'kysely/migration' instead">
393+
/**
394+
* @deprecated import from 'kysely/migration' instead.
395+
*/
396+
export type FileMigrationProviderPath =
397+
KyselyTypeError<"import from 'kysely/migration' instead">
398+
/**
399+
* @deprecated import from 'kysely/migration' instead.
400+
*/
401+
export type FileMigrationProviderProps =
402+
KyselyTypeError<"import from 'kysely/migration' instead">

src/migration/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './file-migration-provider.js'
2+
export * from './migrator.js'

src/migration/migrator.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ export interface Migration {
3939
* import { promises as fs } from 'node:fs'
4040
* import path from 'node:path'
4141
* import * as Sqlite from 'better-sqlite3'
42-
* import {
43-
* FileMigrationProvider,
44-
* Kysely,
45-
* Migrator,
46-
* SqliteDialect
47-
* } from 'kysely'
42+
* import { Kysely, SqliteDialect } from 'kysely'
43+
* import { FileMigrationProvider, Migrator } from 'kysely/migration'
4844
*
4945
* const db = new Kysely<any>({
5046
* dialect: new SqliteDialect({
@@ -119,7 +115,7 @@ export class Migrator {
119115
* import { promises as fs } from 'node:fs'
120116
* import path from 'node:path'
121117
* import * as Sqlite from 'better-sqlite3'
122-
* import { FileMigrationProvider, Migrator } from 'kysely'
118+
* import { FileMigrationProvider, Migrator } from 'kysely/migration'
123119
*
124120
* const migrator = new Migrator({
125121
* db,
@@ -163,7 +159,7 @@ export class Migrator {
163159
* ```ts
164160
* import { promises as fs } from 'node:fs'
165161
* import path from 'node:path'
166-
* import { FileMigrationProvider, Migrator } from 'kysely'
162+
* import { FileMigrationProvider, Migrator } from 'kysely/migration'
167163
*
168164
* const migrator = new Migrator({
169165
* db,
@@ -186,7 +182,7 @@ export class Migrator {
186182
* ```ts
187183
* import { promises as fs } from 'node:fs'
188184
* import path from 'node:path'
189-
* import { FileMigrationProvider, Migrator, NO_MIGRATIONS } from 'kysely'
185+
* import { FileMigrationProvider, Migrator, NO_MIGRATIONS } from 'kysely/migration'
190186
*
191187
* const migrator = new Migrator({
192188
* db,
@@ -264,7 +260,7 @@ export class Migrator {
264260
* ```ts
265261
* import { promises as fs } from 'node:fs'
266262
* import path from 'node:path'
267-
* import { FileMigrationProvider, Migrator } from 'kysely'
263+
* import { FileMigrationProvider, Migrator } from 'kysely/migration'
268264
*
269265
* const migrator = new Migrator({
270266
* db,
@@ -296,7 +292,7 @@ export class Migrator {
296292
* ```ts
297293
* import { promises as fs } from 'node:fs'
298294
* import path from 'node:path'
299-
* import { FileMigrationProvider, Migrator } from 'kysely'
295+
* import { FileMigrationProvider, Migrator } from 'kysely/migration'
300296
*
301297
* const migrator = new Migrator({
302298
* db,

test/node/src/migration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from 'node:path'
22
import { promises as fs } from 'node:fs'
33
import { setTimeout } from 'node:timers/promises'
44

5+
import type { Kysely } from '../../../'
56
import {
67
FileMigrationProvider,
78
type Migration,
@@ -12,8 +13,7 @@ import {
1213
Migrator,
1314
NO_MIGRATIONS,
1415
type MigratorProps,
15-
type Kysely,
16-
} from '../../../'
16+
} from '../../../dist/cjs/migration'
1717

1818
import {
1919
clearDatabase,

0 commit comments

Comments
 (0)