UNPKG

2.37 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="@adonisjs/application/build/adonis-typings" />
3declare 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 * Options accepted by migrator constructor
9 */
10 export type MigratorOptions = {
11 direction: 'up';
12 connectionName?: string;
13 dryRun?: boolean;
14 } | {
15 direction: 'down';
16 batch?: number;
17 connectionName?: string;
18 dryRun?: boolean;
19 };
20 /**
21 * Shape of migrated file within migrator
22 */
23 export type MigratedFileNode = {
24 status: 'completed' | 'error' | 'pending';
25 queries: string[];
26 file: FileNode<unknown>;
27 batch: number;
28 };
29 /**
30 * Shape of migrated file within migrator
31 */
32 export type MigrationListNode = {
33 name: string;
34 status: 'pending' | 'migrated' | 'corrupt';
35 batch?: number;
36 migrationTime?: Date;
37 };
38 /**
39 * Shape of the migrator
40 */
41 export interface MigratorContract extends EventEmitter {
42 dryRun: boolean;
43 direction: 'up' | 'down';
44 status: 'completed' | 'skipped' | 'pending' | 'error';
45 error: null | Error;
46 migratedFiles: {
47 [file: string]: MigratedFileNode;
48 };
49 run(): Promise<void>;
50 getList(): Promise<MigrationListNode[]>;
51 close(): Promise<void>;
52 on(event: 'start', callback: () => void): this;
53 on(event: 'end', callback: () => void): this;
54 on(event: 'acquire:lock', callback: () => void): this;
55 on(event: 'release:lock', callback: () => void): this;
56 on(event: 'create:schema:table', callback: () => void): this;
57 on(event: 'migration:start', callback: (file: MigratedFileNode) => void): this;
58 on(event: 'migration:completed', callback: (file: MigratedFileNode) => void): this;
59 on(event: 'migration:error', callback: (file: MigratedFileNode) => void): this;
60 }
61 /**
62 * Migrator class constructor
63 */
64 const Migrator: {
65 new (db: DatabaseContract, app: ApplicationContract, options: MigratorOptions): MigratorContract;
66 };
67 export default Migrator;
68}