diff --git a/src/commands/migrations/add/add.ts b/src/commands/migrations/add/add.ts index 26232983..8b28cc8e 100644 --- a/src/commands/migrations/add/add.ts +++ b/src/commands/migrations/add/add.ts @@ -1,5 +1,6 @@ import { logError, LogOptions } from "../../../log.js"; import { addMigration, AddMigrationParams } from "../../../modules/migrations/add.js"; +import { MigrationModuleType } from "../../../modules/migrations/models/migration.js"; import { RegisterCommand } from "../../../types/yargs.js"; import { simplifyErrors } from "../../../utils/error.js"; @@ -88,7 +89,7 @@ const resolveParams = (args: AddMigrationCliParams): AddMigrationParams => { return { ...args, - type: args.type as "ts" | "js", + type: args.type as MigrationModuleType, ...orderParams, }; }; diff --git a/src/modules/migrations/add.ts b/src/modules/migrations/add.ts index 8945d571..730fcadf 100644 --- a/src/modules/migrations/add.ts +++ b/src/modules/migrations/add.ts @@ -3,6 +3,7 @@ import { existsSync } from "fs"; import * as path from "path"; import { logInfo, LogOptions } from "../../log.js"; +import { MigrationModuleType } from "./models/migration.js"; import { handleErr } from "./utils/errUtils.js"; import { createFolder, saveFile } from "./utils/fileUtils.js"; import { generateJavascriptMigration, generateTypescriptMigration, getMigrationName } from "./utils/migrationUtils.js"; @@ -11,7 +12,7 @@ export type AddMigrationParams = Readonly< & { name: string; migrationsFolder?: string; - type: "js" | "ts"; + type: MigrationModuleType; } & TimestampOrOrderParams & LogOptions diff --git a/src/modules/migrations/models/migration.ts b/src/modules/migrations/models/migration.ts index ab818852..02fc9936 100644 --- a/src/modules/migrations/models/migration.ts +++ b/src/modules/migrations/models/migration.ts @@ -3,6 +3,8 @@ import { z } from "zod"; export type MigrationOrder = number | Date; +export type MigrationModuleType = "js" | "ts"; + export type MigrationModule = Readonly<{ order: MigrationOrder; run(apiClient: ManagementClient): Promise; diff --git a/src/modules/migrations/utils/migrationUtils.ts b/src/modules/migrations/utils/migrationUtils.ts index 1eba78cb..0307bce3 100644 --- a/src/modules/migrations/utils/migrationUtils.ts +++ b/src/modules/migrations/utils/migrationUtils.ts @@ -8,7 +8,7 @@ import { match, P } from "ts-pattern"; import { logError, logInfo, LogOptions } from "../../../log.js"; import { seriallyReduce } from "../../../utils/requests.js"; -import { isMigrationModule, Migration, MigrationOrder } from "../models/migration.js"; +import { isMigrationModule, Migration, MigrationModuleType, MigrationOrder } from "../models/migration.js"; import { MigrationOperation, MigrationStatus } from "../models/status.js"; import { RunMigrationFilterParams } from "../run.js"; import { WithErr } from "./errUtils.js"; @@ -23,7 +23,7 @@ export const formatDateForFileName = (date: Date) => + `${("0" + date.getUTCMinutes()).slice(-2)}-` + `${("0" + date.getUTCSeconds()).slice(-2)}-`; -export const getMigrationName = (name: string, type: "js" | "ts", prefix: Date | string | undefined) => +export const getMigrationName = (name: string, type: MigrationModuleType, prefix: Date | string | undefined) => `${prefix instanceof Date ? formatDateForFileName(prefix) : prefix ?? ""}${name}.${type}`; export const generateTypescriptMigration = (order: Date | number | undefined): string =>