fix: update tests to reflect migration template changes (#11653)

This commit is contained in:
Simon Garner 2025-09-17 18:37:12 +12:00 committed by GitHub
parent fa3cd436a2
commit 3fac86b60e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 64 additions and 27 deletions

View File

@ -250,6 +250,7 @@ Alternatively, you can also output your migrations as Javascript files using the
```javascript
/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -257,12 +258,18 @@ Alternatively, you can also output your migrations as Javascript files using the
* @implements {MigrationInterface}
*/
module.exports = class PostRefactoringTIMESTAMP {
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(
`ALTER TABLE "post" ALTER COLUMN "title" RENAME TO "name"`,
)
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(
`ALTER TABLE "post" ALTER COLUMN "name" RENAME TO "title"`,
@ -276,6 +283,7 @@ By default, it generates CommonJS JavaScript code with the `o` (alias for `--out
```javascript
/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -283,38 +291,18 @@ By default, it generates CommonJS JavaScript code with the `o` (alias for `--out
* @implements {MigrationInterface}
*/
export class PostRefactoringTIMESTAMP {
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(
`ALTER TABLE "post" ALTER COLUMN "title" RENAME TO "name"`,
)
}
async down(queryRunner) {
await queryRunner.query(
`ALTER TABLE "post" ALTER COLUMN "name" RENAME TO "title"`,
)
}
}
```
By default, it generates CommonJS JavaScript code with the `o` (alias for `--outputJs`) flag, but you can also generate ESM code with the `esm` flag. This is useful for Javascript projects that use ESM:
```javascript
/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
*/
/**
* @class
* @implements {MigrationInterface}
*/
export class PostRefactoringTIMESTAMP {
async up(queryRunner) {
await queryRunner.query(
`ALTER TABLE "post" ALTER COLUMN "title" RENAME TO "name"`,
)
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(
`ALTER TABLE "post" ALTER COLUMN "name" RENAME TO "title"`,

View File

@ -17,6 +17,7 @@ export class TestMigration1610975184784 implements MigrationInterface {
}`,
javascript: `/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -26,11 +27,17 @@ export class TestMigration1610975184784 implements MigrationInterface {
module.exports = class TestMigration1610975184784 {
name = 'TestMigration1610975184784'
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(\`CREATE SEQUENCE "post_id_seq"\`);
await queryRunner.query(\`CREATE TABLE "post" ("id" INT DEFAULT nextval('"post_id_seq"') NOT NULL, "title" varchar NOT NULL, "createdAt" timestamptz NOT NULL DEFAULT now(), CONSTRAINT "PK_be5fda3aac270b134ff9c21cdee" PRIMARY KEY ("id"))\`);
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(\`DROP TABLE "post"\`);
await queryRunner.query(\`DROP SEQUENCE "post_id_seq"\`);

View File

@ -15,6 +15,7 @@ export class TestMigration1610975184784 implements MigrationInterface {
}`,
javascript: `/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -24,10 +25,16 @@ export class TestMigration1610975184784 implements MigrationInterface {
module.exports = class TestMigration1610975184784 {
name = 'TestMigration1610975184784'
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(\`CREATE TABLE "post" ("id" int NOT NULL IDENTITY(1,1), "title" nvarchar(255) NOT NULL, "createdAt" datetime2 NOT NULL CONSTRAINT "DF_fb91bea2d37140a877b775e6b2a" DEFAULT getdate(), CONSTRAINT "PK_be5fda3aac270b134ff9c21cdee" PRIMARY KEY ("id"))\`);
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(\`DROP TABLE "post"\`);
}

View File

@ -15,6 +15,7 @@ export class TestMigration1610975184784 implements MigrationInterface {
}`,
javascript: `/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -24,10 +25,16 @@ export class TestMigration1610975184784 implements MigrationInterface {
module.exports = class TestMigration1610975184784 {
name = 'TestMigration1610975184784'
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(\`CREATE TABLE \\\`post\\\` (\\\`id\\\` int NOT NULL AUTO_INCREMENT, \\\`title\\\` varchar(255) NOT NULL, \\\`createdAt\\\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), PRIMARY KEY (\\\`id\\\`)) ENGINE=InnoDB\`);
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(\`DROP TABLE \\\`post\\\`\`);
}

View File

@ -15,6 +15,7 @@ export class TestMigration1610975184784 implements MigrationInterface {
}`,
javascript: `/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -24,10 +25,16 @@ export class TestMigration1610975184784 implements MigrationInterface {
module.exports = class TestMigration1610975184784 {
name = 'TestMigration1610975184784'
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(\`CREATE TABLE "post" ("id" number GENERATED BY DEFAULT AS IDENTITY, "title" varchar2(255) NOT NULL, "createdAt" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT "PK_be5fda3aac270b134ff9c21cdee" PRIMARY KEY ("id"))\`);
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(\`DROP TABLE "post"\`);
}

View File

@ -15,6 +15,7 @@ export class TestMigration1610975184784 implements MigrationInterface {
}`,
javascript: `/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -24,10 +25,16 @@ export class TestMigration1610975184784 implements MigrationInterface {
module.exports = class TestMigration1610975184784 {
name = 'TestMigration1610975184784'
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(\`CREATE TABLE "post" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_be5fda3aac270b134ff9c21cdee" PRIMARY KEY ("id"))\`);
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(\`DROP TABLE "post"\`);
}

View File

@ -15,6 +15,7 @@ export class TestMigration1610975184784 implements MigrationInterface {
}`,
javascript: `/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -24,10 +25,16 @@ export class TestMigration1610975184784 implements MigrationInterface {
module.exports = class TestMigration1610975184784 {
name = 'TestMigration1610975184784'
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(\`CREATE TABLE "post" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')))\`);
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(\`DROP TABLE "post"\`);
}

View File

@ -13,6 +13,7 @@ export class TestMigration1610975184784 implements MigrationInterface {
`,
javascript: `/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/
/**
@ -21,9 +22,15 @@ export class TestMigration1610975184784 implements MigrationInterface {
*/
module.exports = class TestMigration1610975184784 {
/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
}
/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
}

View File

@ -60,7 +60,7 @@ describe("github issues > #6115 Down migration for enums with defaults are wrong
let table = await queryRunner.getTable("metric")
let defaultOperator = table!.findColumnByName("defaultOperator")
expect(defaultOperator!.enum).to.deep.equal([
expect(defaultOperator!.enum).to.have.members([
"lessthan",
"lessequal",
"equal",