mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: update tests to reflect migration template changes (#11653)
This commit is contained in:
parent
fa3cd436a2
commit
3fac86b60e
@ -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"`,
|
||||
|
||||
@ -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"\`);
|
||||
|
||||
@ -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"\`);
|
||||
}
|
||||
|
||||
@ -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\\\`\`);
|
||||
}
|
||||
|
||||
@ -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"\`);
|
||||
}
|
||||
|
||||
@ -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"\`);
|
||||
}
|
||||
|
||||
@ -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"\`);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
}
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user