forked from tj/node-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
83 lines (75 loc) · 2.31 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import type { EventEmitter } from "events";
type MigrationOptions = {
set?: MigrationSet;
stateStore?: string | FileStore;
migrationsDirectory?: string;
ignoreMissing?: boolean;
filterFunction?: (migration: string) => boolean;
sortFunction?: (migration1: Migration, migration2: Migration) => boolean;
};
type NextFunction = () => void;
/**
* Callback to continue migration.
* Result should be an `Error` if the method failed
* Result should be `null` if the method was successful
*/
type Callback = (result: Error | null) => void;
export default function migrate(
title: string,
up: (next: NextFunction) => void,
down: (next: NextFunction) => void
): void;
export function load(
opts: MigrationOptions,
cb: (err: any, set: MigrationSet) => void
): void;
declare class Migration {
constructor(
title: string,
up: (next: NextFunction) => void,
down: (next: NextFunction) => void,
description: string
);
title: string;
up: (next: NextFunction) => void;
down: (next: NextFunction) => void;
description: string;
timestamp: number | null;
}
export class MigrationSet extends EventEmitter {
constructor(store: FileStore);
addMigration(
title: string,
up: (next: NextFunction) => void,
down: (next: NextFunction) => void
): void;
addMigration(migration: Migration): void;
save(cb: Callback): void;
down(migrationName: string, cb: Callback): void;
down(cb: Callback): void;
up(migrationName: string, cb: Callback): void;
up(cb: Callback): void;
migrate(
direction: "up" | "down",
migrationName: string,
cb: Callback
): void;
migrate(direction: "up" | "down", cb: Callback): void;
migrations: Migration[];
map: { [title: string]: Migration };
lastRun: string | null;
}
/**
* Callback to invoke after loading migration state from filestore
* If loading failed, just the error should be passed as `err`
* If loading succeeded, `err` should be null and `store` should be the migration state that was loaded
*/
type FileStoreLoadCallback = ((err: Error) => void) & ((err: null, store: {
lastRun?: string;
migrations: Pick<Migration, "title" | "description" | "timestamp">[];
}) => void);
declare class FileStore {
constructor(path: string);
save(set: MigrationSet, cb: Callback): void;
load(cb: FileStoreLoadCallback): void;
}