MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / rollup

Function rollup

packages/core/src/utils/AbstractMigrator.ts:147–247  ·  view source on GitHub ↗

* @inheritDoc

(migrations?: string[])

Source from the content-addressed store, hash-verified

145 * @inheritDoc
146 */
147 async rollup(migrations?: string[]): Promise<MigrationResult> {
148 await this.init();
149 const { fs } = await import('@mikro-orm/core/fs-utils');
150
151 const all = await this.discoverMigrations();
152 const executedSet = new Set(await this.storage.executed());
153
154 let toRollup: RunnableMigration[];
155
156 if (migrations && migrations.length > 0) {
157 const requested = new Set(migrations.map(m => this.getMigrationFilename(m)));
158 toRollup = all.filter(m => requested.has(m.name));
159
160 const found = new Set(toRollup.map(m => m.name));
161 const notFound = [...requested].filter(name => !found.has(name));
162
163 if (notFound.length > 0) {
164 throw new Error(`Migrations not found: ${notFound.join(', ')}`);
165 }
166
167 const notExecuted = toRollup.filter(m => !executedSet.has(m.name));
168
169 if (notExecuted.length > 0) {
170 throw new Error(
171 `Cannot roll up migrations that have not been executed: ${notExecuted.map(m => m.name).join(', ')}`,
172 );
173 }
174 } else {
175 toRollup = all.filter(m => executedSet.has(m.name));
176 }
177
178 if (toRollup.length < 2) {
179 throw new Error('At least 2 executed migrations are required for rollup');
180 }
181
182 const withoutPath = toRollup.filter(m => !m.path);
183
184 if (withoutPath.length > 0) {
185 throw new Error(
186 `Cannot roll up migrations without file paths (class-based migrations): ${withoutPath.map(m => m.name).join(', ')}`,
187 );
188 }
189
190 const upBodies: string[] = [];
191 const downBodies: string[] = [];
192 const placeholder = `__mikro_orm_rollup_${Date.now()}__`;
193
194 for (const migration of toRollup) {
195 const source = await fs.readFile(migration.path!);
196 const upBody = this.extractMethodBody(source, 'up');
197 const downBody = this.extractMethodBody(source, 'down');
198
199 if (upBody) {
200 upBodies.push(` // --- merged from ${migration.name} ---\n${upBody}`);
201 }
202
203 if (downBody) {
204 downBodies.unshift(` // --- merged from ${migration.name} ---\n${downBody}`);

Callers

nothing calls this directly

Calls 15

updateStorageFunction · 0.85
filterMethod · 0.80
readFileMethod · 0.80
pushMethod · 0.80
writeFileMethod · 0.80
normalizePathMethod · 0.80
unlinkMethod · 0.80
initMethod · 0.65
executedMethod · 0.65
hasMethod · 0.65
joinMethod · 0.65
generateMethod · 0.65

Tested by

no test coverage detected