1 |
|
2 |
|
3 |
|
4 | import { EventEmitter } from 'events';
|
5 | import { ApplicationContract } from '@ioc:Adonis/Core/Application';
|
6 | import { MigratorOptions, MigratedFileNode, MigratorContract, MigrationListNode } from '@ioc:Adonis/Lucid/Migrator';
|
7 | import { DatabaseContract } from '@ioc:Adonis/Lucid/Database';
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export declare class Migrator extends EventEmitter implements MigratorContract {
|
13 | private db;
|
14 | private app;
|
15 | private options;
|
16 | private client;
|
17 | private config;
|
18 | |
19 |
|
20 |
|
21 | private migrationsConfig;
|
22 | |
23 |
|
24 |
|
25 | private booted;
|
26 | |
27 |
|
28 |
|
29 | private migrationSource;
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | direction: 'up' | 'down';
|
37 | |
38 |
|
39 |
|
40 | dryRun: boolean;
|
41 | |
42 |
|
43 |
|
44 |
|
45 | migratedFiles: {
|
46 | [file: string]: MigratedFileNode;
|
47 | };
|
48 | |
49 |
|
50 |
|
51 | error: null | Error;
|
52 | |
53 |
|
54 |
|
55 | get status(): "error" | "completed" | "pending" | "skipped";
|
56 | constructor(db: DatabaseContract, app: ApplicationContract, options: MigratorOptions);
|
57 | /**
|
58 | * Returns the client for a given schema file. Schema instructions are
|
59 | * wrapped in a transaction unless transaction is not disabled
|
60 | */
|
61 | private getClient;
|
62 | /**
|
63 | * Roll back the transaction when it's client is a transaction client
|
64 | */
|
65 | private rollback;
|
66 | /**
|
67 | * Commits a transaction when it's client is a transaction client
|
68 | */
|
69 | private commit;
|
70 | /**
|
71 | * Writes the migrated file to the migrations table. This ensures that
|
72 | * we are not re-running the same migration again
|
73 | */
|
74 | private recordMigrated;
|
75 | /**
|
76 | * Removes the migrated file from the migrations table. This allows re-running
|
77 | * the migration
|
78 | */
|
79 | private recordRollback;
|
80 | /**
|
81 | * Returns the migration source by ensuring value is a class constructor and
|
82 | * has disableTransactions property.
|
83 | */
|
84 | private getMigrationSource;
|
85 | /**
|
86 | * Executes a given migration node and cleans up any created transactions
|
87 | * in case of failure
|
88 | */
|
89 | private executeMigration;
|
90 | /**
|
91 | * Acquires a lock to disallow concurrent transactions. Only works with
|
92 | * `Mysql`, `PostgreSQL` and `MariaDb` for now.
|
93 | *
|
94 | * Make sure we are acquiring lock outside the transactions, since we want
|
95 | * to block other processes from acquiring the same lock.
|
96 | *
|
97 | * Locks are always acquired in dry run too, since we want to stay close
|
98 | * to the real execution cycle
|
99 | */
|
100 | private acquireLock;
|
101 | /**
|
102 | * Release a lock once complete the migration process. Only works with
|
103 | * `Mysql`, `PostgreSQL` and `MariaDb` for now.
|
104 | */
|
105 | private releaseLock;
|
106 | /**
|
107 | * Makes the migrations table (if missing). Also created in dry run, since
|
108 | * we always reads from the schema table to find which migrations files to
|
109 | * execute and that cannot done without missing table.
|
110 | */
|
111 | private makeMigrationsTable;
|
112 | /**
|
113 | * Returns the latest batch from the migrations
|
114 | * table
|
115 | */
|
116 | private getLatestBatch;
|
117 | /**
|
118 | * Returns an array of files migrated till now
|
119 | */
|
120 | private getMigratedFiles;
|
121 | /**
|
122 | * Returns an array of files migrated till now. The latest
|
123 | * migrations are on top
|
124 | */
|
125 | private getMigratedFilesTillBatch;
|
126 | /**
|
127 | * Boot the migrator to perform actions. All boot methods must
|
128 | * work regardless of dryRun is enabled or not.
|
129 | */
|
130 | private boot;
|
131 | /**
|
132 | * Shutdown gracefully
|
133 | */
|
134 | private shutdown;
|
135 | /**
|
136 | * Migrate up
|
137 | */
|
138 | private runUp;
|
139 | /**
|
140 | * Migrate down (aka rollback)
|
141 | */
|
142 | private runDown;
|
143 | on(event: 'start', callback: () => void): this;
|
144 | on(event: 'end', callback: () => void): this;
|
145 | on(event: 'acquire:lock', callback: () => void): this;
|
146 | on(event: 'release:lock', callback: () => void): this;
|
147 | on(event: 'create:schema:table', callback: () => void): this;
|
148 | on(event: 'migration:start', callback: (file: MigratedFileNode) => void): this;
|
149 | on(event: 'migration:completed', callback: (file: MigratedFileNode) => void): this;
|
150 | on(event: 'migration:error', callback: (file: MigratedFileNode) => void): this;
|
151 | /**
|
152 | * Returns a merged list of completed and pending migrations
|
153 | */
|
154 | getList(): Promise<MigrationListNode[]>;
|
155 | /**
|
156 | * Migrate the database by calling the up method
|
157 | */
|
158 | run(): Promise<void>;
|
159 | /**
|
160 | * Close database connections
|
161 | */
|
162 | close(): Promise<void>;
|
163 | }
|