forked from sequelize/umzug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
149 lines (110 loc) · 4.04 KB
/
Copy pathtypes.ts
File metadata and controls
149 lines (110 loc) · 4.04 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { Migration } from './migration';
import { UmzugStorage } from './storage';
export interface MigrationDefinition {
/**
The `default` module option to support the `export default` syntax from ES6 / TypeScript.
*/
readonly default?: MigrationDefinition;
/**
An async function that performs the task represented by this migration.
*/
up: () => Promise<any>;
/**
An async function that undoes the task represented by this migration.
*/
down: () => Promise<any>;
}
export interface ShortMigrationOptions {
/**
A function that transforms the migrations function (`up` and/or `down`) before it is executed. It receives the migration function and must return another function that works as a migration function in place of it.
This can be used to modify the behavior of the migration function if necessary.
*/
wrap?: (fn: () => Promise<any>) => () => Promise<any>;
/**
A function that specifies how to get a migration object from a file path. It must return an object with `up` and `down` methods.
@default require
*/
customResolver?: (path: string) => MigrationDefinition;
/**
A function that receives the file path of the migration and returns the name of the migration
This can be used to remove file extensions for example.
@default path.basename
@example filePath => path.parse(filePath).name
*/
nameFormatter?: (path: string) => string;
}
export interface UmzugExecuteOptions {
/**
Which migrations to execute (by name).
*/
readonly migrations: string[];
/**
Which migration method to execute.
*/
readonly method: 'up' | 'down';
}
export interface UmzugMigrationParameters {
/**
The parameters that will be used to call the `up` and `down` migration functions.
It can be either an array (which defines the parameters directly), or a function (that will be called right before the migration execution) whose return value is the array of parameters.
@default []
*/
params?: any[] | (() => any[]);
}
export interface UmzugConstructorMigrationOptionsA extends ShortMigrationOptions, UmzugMigrationParameters {
/**
The path to the migrations directory, absolute or relative to `process.cwd()`.
Umzug will automatically retrieve migrations from this directory.
@default path.resolve(process.cwd(), 'migrations')
*/
readonly path?: string;
/**
A Regular Expression which determines whether or not a file found in the given path is a migration.
@default /^\d+[\w-]+\.js$/
*/
readonly pattern?: RegExp;
/**
Recursively search for migrations in the given folder.
@default false
*/
readonly traverseDirectories?: boolean;
}
export interface UmzugConstructorMigrationOptionsB extends Array<Migration>, UmzugMigrationParameters {}
export type UmzugConstructorMigrationOptions = UmzugConstructorMigrationOptionsA | UmzugConstructorMigrationOptionsB;
export interface UmzugConstructorOptions {
/**
* An object implementing the UmzugStorage interface. Defaults to a `JSONStorage` instance
*/
readonly storage?: UmzugStorage;
/**
The logging function.
A function that gets executed everytime migrations start and have ended.
Set to `false` to disable.
*/
readonly logging?: ((...args: any[]) => void) | false;
/**
The sorting function.
A function that sorts migrations.
*/
readonly migrationSorting?: (a: string, b: string) => number;
/**
The options that will setup the detection of migrations.
This can be either a direct array of Migrations or a set of options which define the auto detection of migrations from a folder.
*/
readonly migrations?: UmzugConstructorMigrationOptions;
}
export type UmzugEventNames = 'migrating' | 'reverting' | 'migrated' | 'reverted';
export type UmzugRunOptions =
/** Migration to execute. */
| string
/** Migrations to execute. */
| string[]
/** Object specifying which migrations to execute. */
| {
/** List of migrations to execute (by name). */
migrations?: string[];
/** The migration to start executing from. The given migration is not executed itself, only the ones after it. */
from?: string;
/** The last migration to execute (included). */
to?: string | 0;
};