mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-22 10:32:40 +08:00
feat(ql3): rehearse legacy sqlite upgrade
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { readPrivateLocalCommandFile } from '@qinglong/local-command-file';
|
||||
|
||||
import { runLegacyCrontabAdoptionCommandFile } from './adoption';
|
||||
import {
|
||||
isLocalSqliteAdoptionProductOperation,
|
||||
type LocalSqliteAdoptionProductOperation,
|
||||
} from './sqlite-adoption/contract';
|
||||
import type { LocalSqliteAdoptionProductCommandResult } from './sqlite-adoption/command';
|
||||
|
||||
export type LocalAdoptionProductCommandResult =
|
||||
| Awaited<ReturnType<typeof runLegacyCrontabAdoptionCommandFile>>
|
||||
| LocalSqliteAdoptionProductCommandResult;
|
||||
|
||||
function operation(value: unknown): unknown {
|
||||
return value && typeof value === 'object' && !Array.isArray(value)
|
||||
? (value as { readonly operation?: unknown }).operation
|
||||
: undefined;
|
||||
}
|
||||
|
||||
export async function runLocalAdoptionProductCommandFile(
|
||||
commandFilePath: string,
|
||||
): Promise<Readonly<LocalAdoptionProductCommandResult>> {
|
||||
let candidate: unknown;
|
||||
try {
|
||||
candidate = readPrivateLocalCommandFile(commandFilePath);
|
||||
} catch {
|
||||
// Preserve the established legacy error mapping for unreadable files.
|
||||
return runLegacyCrontabAdoptionCommandFile(commandFilePath);
|
||||
}
|
||||
const selected = operation(candidate);
|
||||
if (!isLocalSqliteAdoptionProductOperation(selected)) {
|
||||
return runLegacyCrontabAdoptionCommandFile(commandFilePath);
|
||||
}
|
||||
const { runLocalSqliteAdoptionProductCommand } = await import(
|
||||
'./sqlite-adoption/command.js'
|
||||
);
|
||||
return runLocalSqliteAdoptionProductCommand(
|
||||
candidate as {
|
||||
readonly operation: LocalSqliteAdoptionProductOperation;
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user