Skip to content

Commit

Permalink
fix: resolve migration for UpdateDateColumn without ON UPDATE clause (#…
Browse files Browse the repository at this point in the history
…7057)

Closes: #6995
  • Loading branch information
jafio committed Jan 12, 2021
1 parent d27dd2a commit ddd8cbc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/metadata/ColumnMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ export class ColumnMetadata {
this.type = options.connection.driver.mappedDataTypes.updateDate;
if (!this.default)
this.default = () => options.connection.driver.mappedDataTypes.updateDateDefault;
if (!this.onUpdate)
this.onUpdate = options.connection.driver.mappedDataTypes.updateDateDefault;
if (this.precision === undefined && options.connection.driver.mappedDataTypes.updateDatePrecision)
this.precision = options.connection.driver.mappedDataTypes.updateDatePrecision;
}
Expand Down
16 changes: 16 additions & 0 deletions test/github-issues/6995/entity/default-update-date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, Entity } from '../../../../src';

@Entity()
export class DefaultUpdateDate {

@PrimaryGeneratedColumn({
type: "int"
})
public id: number;

@CreateDateColumn()
public createdDate: Date;

@UpdateDateColumn()
public updatedDate: Date;
}
25 changes: 25 additions & 0 deletions test/github-issues/6995/issue-6995.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "reflect-metadata";
import { Connection } from "../../../src";
import { createTestingConnections, closeTestingConnections } from "../../utils/test-utils";
import { DefaultUpdateDate } from './entity/default-update-date';

describe("github issues > #6995 Generating migrations for UpdateDateColumn should generate on update clause", () => {

let connections: Connection[];
before(async () => connections = await createTestingConnections({
migrations: [],
enabledDrivers: ["mysql", "mariadb"],
schemaCreate: false,
dropSchema: true,
entities: [DefaultUpdateDate]
}));
after(() => closeTestingConnections(connections));

it("should create migration with default ON UPDATE clause", () => Promise.all(connections.map(async connection => {

const sqlInMemory = await connection.driver.createSchemaBuilder().log();
sqlInMemory.upQueries.filter(i => i.query.includes("ON UPDATE")).length.should.be.greaterThan(0);

})));

});

0 comments on commit ddd8cbc

Please sign in to comment.