diff --git a/docs/docs/advanced-topics/1-migrations.md b/docs/docs/advanced-topics/1-migrations.md index e0bb004a8..08f2796a2 100644 --- a/docs/docs/advanced-topics/1-migrations.md +++ b/docs/docs/advanced-topics/1-migrations.md @@ -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"`, diff --git a/test/functional/commands/templates/generate/cockroachdb.ts b/test/functional/commands/templates/generate/cockroachdb.ts index 4a75d88fc..b24ce2b15 100644 --- a/test/functional/commands/templates/generate/cockroachdb.ts +++ b/test/functional/commands/templates/generate/cockroachdb.ts @@ -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"\`); diff --git a/test/functional/commands/templates/generate/mssql.ts b/test/functional/commands/templates/generate/mssql.ts index ed7c2db90..2884c7ad6 100644 --- a/test/functional/commands/templates/generate/mssql.ts +++ b/test/functional/commands/templates/generate/mssql.ts @@ -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"\`); } diff --git a/test/functional/commands/templates/generate/mysql.ts b/test/functional/commands/templates/generate/mysql.ts index 05b04be89..a9db6565b 100644 --- a/test/functional/commands/templates/generate/mysql.ts +++ b/test/functional/commands/templates/generate/mysql.ts @@ -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\\\`\`); } diff --git a/test/functional/commands/templates/generate/oracle.ts b/test/functional/commands/templates/generate/oracle.ts index aeea51b3a..0559ffe29 100644 --- a/test/functional/commands/templates/generate/oracle.ts +++ b/test/functional/commands/templates/generate/oracle.ts @@ -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"\`); } diff --git a/test/functional/commands/templates/generate/postgres.ts b/test/functional/commands/templates/generate/postgres.ts index 0d07f3f1c..1ebcf1c3d 100644 --- a/test/functional/commands/templates/generate/postgres.ts +++ b/test/functional/commands/templates/generate/postgres.ts @@ -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"\`); } diff --git a/test/functional/commands/templates/generate/sqlite.ts b/test/functional/commands/templates/generate/sqlite.ts index 26bdddcf0..c24985368 100644 --- a/test/functional/commands/templates/generate/sqlite.ts +++ b/test/functional/commands/templates/generate/sqlite.ts @@ -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"\`); } diff --git a/test/functional/commands/templates/result-templates-create.ts b/test/functional/commands/templates/result-templates-create.ts index b45e94bb8..541722819 100644 --- a/test/functional/commands/templates/result-templates-create.ts +++ b/test/functional/commands/templates/result-templates-create.ts @@ -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) { } diff --git a/test/github-issues/6115/issue-6115.ts b/test/github-issues/6115/issue-6115.ts index 31f7ea694..94fc778f5 100644 --- a/test/github-issues/6115/issue-6115.ts +++ b/test/github-issues/6115/issue-6115.ts @@ -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",