-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check for version of MariaDB before extracting COLUMN_DEFAULT (#…
…4783) Added VersionUtils module to make it easier to compare coerce and compare versions of MariaDB database. See https://mariadb.com/kb/en/library/information-schema-columns-table/ Relevant excerpt for `COLUMN_DEFAULT`: > Default value for the column. From MariaDB 10.2.7, literals are quoted > to distinguish them from expressions. NULL means that the column has no > default. In MariaDB 10.2.6 and earlier, no quotes were used for any type > of default and NULL can either mean that there is no default, or that > the default column value is NULL.
- Loading branch information
Showing
5 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export type Version = [number, number, number]; | ||
|
||
export class VersionUtils { | ||
static isGreaterOrEqual(version: string, targetVersion: string): boolean { | ||
const v1 = parseVersion(version); | ||
const v2 = parseVersion(targetVersion); | ||
|
||
return v1[0] > v2[0] || | ||
v1[0] === v2[0] && v1[1] > v2[1] || | ||
v1[0] === v2[0] && v1[1] === v2[1] && v1[2] >= v2[2]; | ||
} | ||
} | ||
|
||
function parseVersion(version: string = ""): Version { | ||
const v: Version = [0, 0, 0]; | ||
|
||
version.split(".").forEach((value, i) => v[i] = parseInt(value, 10)); | ||
|
||
return v; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CreateDateColumn } from "../../../../src"; | ||
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import { Entity } from "../../../../src/decorator/entity/Entity"; | ||
|
||
@Entity() | ||
export class Item { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@CreateDateColumn() | ||
date: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import "reflect-metadata"; | ||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; | ||
import {Connection} from "../../../src/connection/Connection"; | ||
import {expect} from "chai"; | ||
import { VersionUtils } from "../../../src/util/VersionUtils"; | ||
|
||
describe("github issues > 4782 mariadb driver wants to recreate create/update date columns CURRENT_TIMESTAMP(6) === current_timestamp(6)", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
// logging: true, | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["mysql", "mariadb"] | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should not want to execute migrations twice", () => Promise.all(connections.map(async connection => { | ||
const sql1 = await connection.driver.createSchemaBuilder().log(); | ||
expect(sql1.upQueries).to.eql([]); | ||
}))); | ||
|
||
describe("VersionUtils", () => { | ||
describe("isGreaterOrEqual", () => { | ||
it("should return false when comparing invalid versions", () => { | ||
expect(VersionUtils.isGreaterOrEqual("", "")).to.equal(false); | ||
}); | ||
|
||
it("should return false when targetVersion is larger", () => { | ||
expect(VersionUtils.isGreaterOrEqual("1.2.3", "1.2.4")).to.equal(false); | ||
expect(VersionUtils.isGreaterOrEqual("1.2.3", "1.4.3")).to.equal(false); | ||
expect(VersionUtils.isGreaterOrEqual("1.2.3", "2.2.3")).to.equal(false); | ||
expect(VersionUtils.isGreaterOrEqual("1.2", "1.3")).to.equal(false); | ||
expect(VersionUtils.isGreaterOrEqual("1", "2")).to.equal(false); | ||
expect(VersionUtils.isGreaterOrEqual(undefined as unknown as string, "0.0.1")).to.equal(false); | ||
}); | ||
|
||
it("should return true when targetVersion is smaller", () => { | ||
|
||
expect(VersionUtils.isGreaterOrEqual("1.2.3", "1.2.2")).to.equal(true); | ||
expect(VersionUtils.isGreaterOrEqual("1.2.3", "1.1.3")).to.equal(true); | ||
expect(VersionUtils.isGreaterOrEqual("1.2.3", "0.2.3")).to.equal(true); | ||
expect(VersionUtils.isGreaterOrEqual("1.2", "1.2")).to.equal(true); | ||
expect(VersionUtils.isGreaterOrEqual("1", "1")).to.equal(true); | ||
}); | ||
|
||
it("should work with mariadb-style versions", () => { | ||
const dbVersion = "10.4.8-MariaDB-1:10.4.8+maria~bionic"; | ||
expect(VersionUtils.isGreaterOrEqual("10.4.9", dbVersion)).to.equal(true); | ||
expect(VersionUtils.isGreaterOrEqual("10.4.8", dbVersion)).to.equal(true); | ||
expect(VersionUtils.isGreaterOrEqual("10.4.7", dbVersion)).to.equal(false); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |