Skip to content

Commit

Permalink
Extract MigrationModuleType type in addMigration
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriLojda committed Nov 5, 2024
1 parent 9b2fc5e commit 9198afa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/commands/migrations/add/add.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -88,7 +89,7 @@ const resolveParams = (args: AddMigrationCliParams): AddMigrationParams => {

return {
...args,
type: args.type as "ts" | "js",
type: args.type as MigrationModuleType,
...orderParams,
};
};
3 changes: 2 additions & 1 deletion src/modules/migrations/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -11,7 +12,7 @@ export type AddMigrationParams = Readonly<
& {
name: string;
migrationsFolder?: string;
type: "js" | "ts";
type: MigrationModuleType;
}
& TimestampOrOrderParams
& LogOptions
Expand Down
2 changes: 2 additions & 0 deletions src/modules/migrations/models/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/migrations/utils/migrationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 =>
Expand Down

0 comments on commit 9198afa

Please sign in to comment.