Skip to content

Commit

Permalink
fix: Do not add NULL/NOT NULL for stored columns (#7708)
Browse files Browse the repository at this point in the history
closes: #7698
  • Loading branch information
tomlaws committed Jun 21, 2021
1 parent b690c27 commit 3c33e9f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/driver/mysql/MysqlQueryRunner.ts
Expand Up @@ -1867,8 +1867,8 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
c += ` COLLATE "${column.collation}"`;

const isMariaDb = this.driver.options.type === "mariadb";
if (isMariaDb && column.asExpression && (column.generatedType || "VIRTUAL") === "VIRTUAL") {
// do nothing - MariaDB does not support NULL/NOT NULL expressions for VIRTUAL columns
if (isMariaDb && column.asExpression && ["VIRTUAL", "STORED"].includes((column.generatedType || "VIRTUAL"))) {
// do nothing - MariaDB does not support NULL/NOT NULL expressions for VIRTUAL columns and STORED columns
} else {
if (!column.isNullable)
c += " NOT NULL";
Expand Down
21 changes: 21 additions & 0 deletions test/github-issues/7698/entity/Test.ts
@@ -0,0 +1,21 @@
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src";

@Entity()
export class Test {

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

@Column()
firstName: string

@Column()
lastName: string

@Column({
generatedType: 'STORED',
// asExpression is needed here or generatedType above will be ignored
asExpression: "concat(`firstName`,' ',`lastName`)",
})
name: string;
}
25 changes: 25 additions & 0 deletions test/github-issues/7698/issue-7698.ts
@@ -0,0 +1,25 @@
import "reflect-metadata";
import { Connection } from "../../../src";
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils";
import { Test } from "./entity/Test";

describe("github issues > #7698 MariaDB STORED columns don't accept [NULL | NOT NULL]", () => {

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

it("should not generate queries with NULL or NOT NULL for stored columns in mariadb", () => Promise.all(connections.map(async connection => {
await connection.driver.createSchemaBuilder().build();
const sqlInMemory = await connection.driver.createSchemaBuilder().log();
sqlInMemory.upQueries.length.should.be.greaterThan(0);
})));
});

0 comments on commit 3c33e9f

Please sign in to comment.