Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration:generate issue with onUpdate using mariadb 10.4 #6714

Merged
merged 5 commits into from Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/driver/mysql/MysqlQueryRunner.ts
Expand Up @@ -1321,7 +1321,9 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
}

if (dbColumn["EXTRA"].indexOf("on update") !== -1) {
tableColumn.onUpdate = dbColumn["EXTRA"].substring(dbColumn["EXTRA"].indexOf("on update") + 10);
// New versions of MariaDB return expressions in lowercase. We need to set it in
// uppercase so the comparison in MysqlDriver#compareExtraValues does not fail.
tableColumn.onUpdate = dbColumn["EXTRA"].substring(dbColumn["EXTRA"].indexOf("on update") + 10).toUpperCase();
}

if (dbColumn["GENERATION_EXPRESSION"]) {
Expand Down
17 changes: 17 additions & 0 deletions test/github-issues/6714/entity/session.ts
@@ -0,0 +1,17 @@
import { Entity, PrimaryGeneratedColumn, Column } from "../../../../src";

@Entity({ name: "Session" })
export class Session {

@PrimaryGeneratedColumn()
id?: number;

@Column({
type: "timestamp",
precision: 3,
default: () => "CURRENT_TIMESTAMP(3)",
onUpdate: "CURRENT_TIMESTAMP(3)",
})
ts: Date;

}
15 changes: 15 additions & 0 deletions test/github-issues/6714/entity/sessionchanged.ts
@@ -0,0 +1,15 @@
import { Entity, PrimaryGeneratedColumn, Column } from "../../../../src";

@Entity({ name: "Session" })
export class Session {
@PrimaryGeneratedColumn()
id?: number;

@Column({
type: "timestamp",
precision: 4,
default: () => "CURRENT_TIMESTAMP(4)",
onUpdate: "CURRENT_TIMESTAMP(4)",
})
ts: Date;
}
59 changes: 59 additions & 0 deletions test/github-issues/6714/issue-6714.ts
@@ -0,0 +1,59 @@
import "reflect-metadata";
import {
createTestingConnections,
closeTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils";
import { Connection } from "../../../src/connection/Connection";
import { expect } from "chai";
import { Session as baseEntity } from "./entity/session";
import { Session as changedEntity } from "./entity/sessionchanged";

describe("github issues > #6714 Migration:generate issue with onUpdate using mariadb 10.4", () => {
it("dont change anything", async () => {
let connections: Connection[];
connections = await createTestingConnections({
entities: [baseEntity],
schemaCreate: false,
dropSchema: true,
enabledDrivers: ["mariadb"],
});
await reloadTestingDatabases(connections);
await Promise.all(
connections.map(async (connection) => {
const schemaBuilder = connection.driver.createSchemaBuilder();
const syncQueries = await schemaBuilder.log();
expect(syncQueries.downQueries).to.be.eql([]);
expect(syncQueries.upQueries).to.be.eql([]);
})
);
await closeTestingConnections(connections);
});
it("recognizing on update changes", async () => {
// this connection create database with a Session entity
const baseConnections = await createTestingConnections({
entities: [baseEntity],
schemaCreate: true, // create the database
dropSchema: true,
enabledDrivers: ["mariadb"],
});
// this connection change Session entity on update value
const connections = await createTestingConnections({
entities: [changedEntity],
schemaCreate: false, // don't change the entity
dropSchema: false,
enabledDrivers: ["mariadb"],
name: "test",
});
await Promise.all(
connections.map(async (connection) => {
const schemaBuilder = connection.driver.createSchemaBuilder();
const syncQueries = await schemaBuilder.log();
expect(syncQueries.downQueries.length).not.to.be.eql(0);
expect(syncQueries.upQueries.length).not.to.be.eql(0);
})
);
await closeTestingConnections(baseConnections);
await closeTestingConnections(connections);
});
});