Skip to content

Commit

Permalink
fix: MariaDB VIRTUAL + [NOT NULL|NULL] error (#7022)
Browse files Browse the repository at this point in the history
* Fix MariaDB VIRTUAL [NOT NULL|NULL] error

Fixes #2691

query failed: ALTER TABLE `customer` CHANGE `fullName` `fullName` varchar(255) AS (CONCAT(`firstName`, ' ', `lastName`)) VIRTUAL NULL
error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1

* slightly change code style to improve readability

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
  • Loading branch information
Maczuga and pleerock committed Feb 8, 2021
1 parent cdace6e commit 82f2b75
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/driver/mysql/MysqlQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1857,10 +1857,17 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
c += ` CHARACTER SET "${column.charset}"`;
if (column.collation)
c += ` COLLATE "${column.collation}"`;
if (!column.isNullable)
c += " NOT NULL";
if (column.isNullable)
c += " NULL";

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
} else {
if (!column.isNullable)
c += " NOT NULL";
if (column.isNullable)
c += " NULL";
}

if (column.isPrimary && !skipPrimary)
c += " PRIMARY KEY";
if (column.isGenerated && column.generationStrategy === "increment") // don't use skipPrimary here since updates can update already exist primary without auto inc.
Expand Down

0 comments on commit 82f2b75

Please sign in to comment.