1 |
|
2 |
|
3 | declare module '@ioc:Adonis/Lucid/Migrator' {
|
4 | import { EventEmitter } from 'events';
|
5 | import { ApplicationContract } from '@ioc:Adonis/Core/Application';
|
6 | import { FileNode, DatabaseContract } from '@ioc:Adonis/Lucid/Database';
|
7 | |
8 |
|
9 |
|
10 | export type MigratorOptions = {
|
11 | direction: 'up';
|
12 | connectionName?: string;
|
13 | dryRun?: boolean;
|
14 | disableLocks?: boolean;
|
15 | } | {
|
16 | direction: 'down';
|
17 | batch?: number;
|
18 | connectionName?: string;
|
19 | dryRun?: boolean;
|
20 | disableLocks?: boolean;
|
21 | };
|
22 | |
23 |
|
24 |
|
25 | export type MigratedFileNode = {
|
26 | status: 'completed' | 'error' | 'pending';
|
27 | queries: string[];
|
28 | file: FileNode<unknown>;
|
29 | batch: number;
|
30 | };
|
31 | |
32 |
|
33 |
|
34 | export type MigrationListNode = {
|
35 | name: string;
|
36 | status: 'pending' | 'migrated' | 'corrupt';
|
37 | batch?: number;
|
38 | migrationTime?: Date;
|
39 | };
|
40 | |
41 |
|
42 |
|
43 | export interface MigratorContract extends EventEmitter {
|
44 | dryRun: boolean;
|
45 | disableLocks: boolean;
|
46 | version: number;
|
47 | direction: 'up' | 'down';
|
48 | status: 'completed' | 'skipped' | 'pending' | 'error';
|
49 | error: null | Error;
|
50 | migratedFiles: {
|
51 | [file: string]: MigratedFileNode;
|
52 | };
|
53 | run(): Promise<void>;
|
54 | getList(): Promise<MigrationListNode[]>;
|
55 | close(): Promise<void>;
|
56 | on(event: 'start', callback: () => void): this;
|
57 | on(event: 'end', callback: () => void): this;
|
58 | on(event: 'acquire:lock', callback: () => void): this;
|
59 | on(event: 'release:lock', callback: () => void): this;
|
60 | on(event: 'create:schema:table', callback: () => void): this;
|
61 | on(event: 'create:schema_versions:table', callback: () => void): this;
|
62 | on(event: 'upgrade:version', callback: (payload: {
|
63 | from: number;
|
64 | to: number;
|
65 | }) => void): this;
|
66 | on(event: 'migration:start', callback: (file: MigratedFileNode) => void): this;
|
67 | on(event: 'migration:completed', callback: (file: MigratedFileNode) => void): this;
|
68 | on(event: 'migration:error', callback: (file: MigratedFileNode) => void): this;
|
69 | }
|
70 | |
71 |
|
72 |
|
73 | const Migrator: {
|
74 | new (db: DatabaseContract, app: ApplicationContract, options: MigratorOptions): MigratorContract;
|
75 | };
|
76 | export default Migrator;
|
77 | }
|