/
types.ts
80 lines (68 loc) · 1.97 KB
/
types.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
export type MigrateDirection = 'up' | 'down';
export type CreateMigrationHandler = (options: IMigrationOptions) => string;
export type ConnectionHandler = (...args: any[]) => Promise<boolean>;
// Events:
//
// created { name, filename }
// filtered { filenames, direction, name, levels }
// loaded { filenames, migrations }
// migration { type, message, ok, count }
// up { name }
// down { name }
// active [migration_name, direction];
// revert { names }
export const EVENTS = ['created', 'filtered', 'loaded', 'migration', 'up', 'down', 'active', 'revert'] as const;
export type Event = typeof EVENTS[number];
export type Events = Record<keyof Event, ((...args: any[]) => void)[]>;
export interface IMigration<C extends ConnectionHandler = ConnectionHandler> {
name: string;
readonly description: string;
readonly filename: string;
up: (conn: C) => Promise<any>;
down: (conn: C) => Promise<any>;
}
export interface IFilteredMigration {
config: IMygra;
files: string[];
}
export interface IMigrationOptions {
readonly name?: string;
description?: string;
template?: string;
table?: string;
defaults?: boolean;
columns?: string[]
up?: string;
down?: string;
[key: string]: any;
}
export interface IMygraConfig {
readonly initialized: boolean;
directory: string;
active: [string, MigrateDirection];
reverts: [string[], MigrateDirection];
extension: string;
templatePrefix: boolean;
}
export interface IMygra<C extends ConnectionHandler = ConnectionHandler> extends IMygraConfig {
templates?: Record<string, CreateMigrationHandler>;
connection?: C;
events?: Events;
}
export interface IMigrationResult {
names?: string[];
type?: MigrateDirection;
ok: boolean;
message: string | Error;
count: number;
success?: number;
failed?: number;
migrated?: IMigration[];
isPreview?: boolean;
}
export interface IMigrationCreateResult {
ok: boolean;
name: string;
filename: string;
message: string | Error;
}