feat(types): move Emigrate types to separate package and improve types (#41)
* feat(types): move Emigrate types to separate package Also refactor the types to use discriminating unions for easier error handling and such. Errors passed to storage plugins should now be serialized and storage plugins are expected to return already serialized errors on failed history entries. * fix(mysql): handle the new type changes * fix(storage-fs): handle the new type changes * feat(cli): better error handling and types Adapt to the new types from the @emigrate/types package, like discriminating union types and serializing and deserializing errors
This commit is contained in:
parent
afe56594c5
commit
cae6d11d53
38 changed files with 630 additions and 259 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import path from 'node:path';
|
||||
import { type MigrationHistoryEntry, type MigrationMetadataFinished } from '@emigrate/plugin-tools/types';
|
||||
import { type MigrationHistoryEntry, type MigrationMetadataFinished } from '@emigrate/types';
|
||||
import { withLeadingPeriod } from './with-leading-period.js';
|
||||
import { MigrationHistoryError } from './errors.js';
|
||||
|
||||
|
|
@ -8,7 +8,22 @@ export const toMigrationMetadata = (
|
|||
{ cwd, directory }: { cwd: string; directory: string },
|
||||
): MigrationMetadataFinished => {
|
||||
const filePath = path.resolve(cwd, directory, entry.name);
|
||||
const finishedMigration: MigrationMetadataFinished = {
|
||||
|
||||
if (entry.status === 'failed') {
|
||||
return {
|
||||
name: entry.name,
|
||||
status: entry.status,
|
||||
filePath,
|
||||
relativeFilePath: path.relative(cwd, filePath),
|
||||
extension: withLeadingPeriod(path.extname(entry.name)),
|
||||
directory,
|
||||
cwd,
|
||||
duration: 0,
|
||||
error: MigrationHistoryError.fromHistoryEntry(entry),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
name: entry.name,
|
||||
status: entry.status,
|
||||
filePath,
|
||||
|
|
@ -18,13 +33,4 @@ export const toMigrationMetadata = (
|
|||
cwd,
|
||||
duration: 0,
|
||||
};
|
||||
|
||||
if (entry.status === 'failed') {
|
||||
finishedMigration.error = new MigrationHistoryError(
|
||||
`Migration ${entry.name} is in a failed state, it should be fixed and removed`,
|
||||
entry,
|
||||
);
|
||||
}
|
||||
|
||||
return finishedMigration;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue