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

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

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

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

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

15
    builder(args: yargs.Argv) {
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

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

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

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

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

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

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

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

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

97
}
98
`
99
    }
100

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

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

120
    async up(queryRunner) {
121
    }
122

123
    async down(queryRunner) {
124
    }
125

126
}
127
`
128
    }
129
}
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

© 2025 Coveralls, Inc