• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 19549987525

20 Nov 2025 08:11PM UTC coverage: 80.769% (+4.3%) from 76.433%
19549987525

push

github

web-flow
ci: run tests on commits to master and next (#11783)

Co-authored-by: Oleg "OSA413" Sokolov <OSA413@users.noreply.github.com>

26500 of 32174 branches covered (82.36%)

Branch coverage included in aggregate %.

91252 of 113615 relevant lines covered (80.32%)

88980.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.52
/src/commands/MigrationCreateCommand.ts
1
import ansi from "ansis"
26✔
2
import path from "path"
26✔
3
import yargs from "yargs"
26✔
4
import { PlatformTools } from "../platform/PlatformTools"
26✔
5
import { camelCase } from "../util/StringUtils"
26✔
6
import { CommandUtils } from "./CommandUtils"
26✔
7

26✔
8
/**
26✔
9
 * Creates a new migration file.
26✔
10
 */
26✔
11
export class MigrationCreateCommand implements yargs.CommandModule {
234✔
12
    command = "migration:create <path>"
234✔
13
    describe = "Creates a new migration file."
234✔
14

234✔
15
    builder(args: yargs.Argv) {
234✔
16
        return args
×
17
            .positional("path", {
×
18
                type: "string",
×
19
                describe: "Path of the migration file",
×
20
                demandOption: true,
×
21
            })
×
22
            .option("o", {
×
23
                alias: "outputJs",
×
24
                type: "boolean",
×
25
                default: false,
×
26
                describe:
×
27
                    "Generate a migration file on Javascript instead of Typescript",
×
28
            })
×
29
            .option("esm", {
×
30
                type: "boolean",
×
31
                default: false,
×
32
                describe:
×
33
                    "Generate a migration file on ESM instead of CommonJS",
×
34
            })
×
35
            .option("t", {
×
36
                alias: "timestamp",
×
37
                type: "number",
×
38
                default: false,
×
39
                describe: "Custom timestamp for the migration name",
×
40
            })
×
41
    }
×
42

234✔
43
    async handler(args: yargs.Arguments<any & { path: string }>) {
234✔
44
        try {
69✔
45
            const timestamp = CommandUtils.getTimestamp(args.timestamp)
69✔
46
            const inputPath = args.path.startsWith("/")
69✔
47
                ? args.path
69!
48
                : path.resolve(process.cwd(), args.path)
69✔
49
            const filename = path.basename(inputPath)
69✔
50
            const fullPath =
69✔
51
                path.dirname(inputPath) + "/" + timestamp + "-" + filename
69✔
52

69✔
53
            const fileContent = args.outputJs
69✔
54
                ? MigrationCreateCommand.getJavascriptTemplate(
69✔
55
                      filename,
23✔
56
                      timestamp,
23✔
57
                      args.esm,
23✔
58
                  )
69✔
59
                : MigrationCreateCommand.getTemplate(filename, timestamp)
69✔
60

69✔
61
            await CommandUtils.createFile(
69✔
62
                fullPath + (args.outputJs ? ".js" : ".ts"),
69✔
63
                fileContent,
69✔
64
            )
69✔
65
            console.log(
69✔
66
                `Migration ${ansi.blue(
69✔
67
                    fullPath + (args.outputJs ? ".js" : ".ts"),
69✔
68
                )} has been generated successfully.`,
69✔
69
            )
69✔
70
        } catch (err) {
69!
71
            PlatformTools.logCmdErr("Error during migration creation:", err)
×
72
            process.exit(1)
×
73
        }
×
74
    }
69✔
75

234✔
76
    // -------------------------------------------------------------------------
234✔
77
    // Protected Static Methods
234✔
78
    // -------------------------------------------------------------------------
234✔
79

234✔
80
    /**
234✔
81
     * Gets contents of the migration file.
234✔
82
     */
234✔
83
    protected static getTemplate(name: string, timestamp: number): string {
234✔
84
        return `import { MigrationInterface, QueryRunner } from "typeorm";
46✔
85

46✔
86
export class ${camelCase(
46✔
87
            name,
46✔
88
            true,
46✔
89
        )}${timestamp} implements MigrationInterface {
46✔
90

46✔
91
    public async up(queryRunner: QueryRunner): Promise<void> {
46✔
92
    }
46✔
93

46✔
94
    public async down(queryRunner: QueryRunner): Promise<void> {
46✔
95
    }
46✔
96

46✔
97
}
46✔
98
`
46✔
99
    }
46✔
100

234✔
101
    /**
234✔
102
     * Gets contents of the migration file in Javascript.
234✔
103
     */
234✔
104
    protected static getJavascriptTemplate(
234✔
105
        name: string,
23✔
106
        timestamp: number,
23✔
107
        esm: boolean,
23✔
108
    ): string {
23✔
109
        const exportMethod = esm ? "export" : "module.exports ="
23!
110
        return `/**
23✔
111
 * @typedef {import('typeorm').MigrationInterface} MigrationInterface
23✔
112
 * @typedef {import('typeorm').QueryRunner} QueryRunner
23✔
113
 */
23✔
114

23✔
115
/**
23✔
116
 * @class
23✔
117
 * @implements {MigrationInterface}
23✔
118
 */
23✔
119
${exportMethod} class ${camelCase(name, true)}${timestamp} {
23✔
120

23✔
121
    /**
23✔
122
     * @param {QueryRunner} queryRunner
23✔
123
     */
23✔
124
    async up(queryRunner) {
23✔
125
    }
23✔
126

23✔
127
    /**
23✔
128
     * @param {QueryRunner} queryRunner
23✔
129
     */
23✔
130
    async down(queryRunner) {
23✔
131
    }
23✔
132

23✔
133
}
23✔
134
`
23✔
135
    }
23✔
136
}
234✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc