diff --git a/src/utils/importSQL/mariadb.js b/src/utils/importSQL/mariadb.js index f7986fb51..f630928f8 100644 --- a/src/utils/importSQL/mariadb.js +++ b/src/utils/importSQL/mariadb.js @@ -56,7 +56,13 @@ export function fromMariaDB(ast, diagramDb = DB.GENERIC) { field.increment = false; if (d.auto_increment) field.increment = true; field.notNull = false; - if (d.nullable) field.notNull = true; + // `nullable` is a node for BOTH markers: `NULL` gives + // { type: "null" } and `NOT NULL` gives { type: "not null" }, + // so testing it for truthiness marked an explicitly nullable + // column as NOT NULL. Only an omitted marker is undefined. + if (d.nullable && d.nullable.type !== "null") { + field.notNull = true; + } field.primary = false; if (d.primary_key) field.primary = true; field.default = ""; diff --git a/src/utils/importSQL/mssql.js b/src/utils/importSQL/mssql.js index e9aea86db..09fc0482b 100644 --- a/src/utils/importSQL/mssql.js +++ b/src/utils/importSQL/mssql.js @@ -68,7 +68,13 @@ export function fromMSSQL(ast, diagramDb = DB.GENERIC) { field.increment = false; if (d.auto_increment) field.increment = true; field.notNull = false; - if (d.nullable) field.notNull = true; + // `nullable` is a node for BOTH markers: `NULL` gives + // { type: "null" } and `NOT NULL` gives { type: "not null" }, + // so testing it for truthiness marked an explicitly nullable + // column as NOT NULL. Only an omitted marker is undefined. + if (d.nullable && d.nullable.type !== "null") { + field.notNull = true; + } field.primary = false; if (d.primary_key) field.primary = true; field.default = ""; diff --git a/src/utils/importSQL/mysql.js b/src/utils/importSQL/mysql.js index 6bf06f7f2..318f2a1ee 100644 --- a/src/utils/importSQL/mysql.js +++ b/src/utils/importSQL/mysql.js @@ -56,7 +56,13 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) { field.increment = false; if (d.auto_increment) field.increment = true; field.notNull = false; - if (d.nullable) field.notNull = true; + // `nullable` is a node for BOTH markers: `NULL` gives + // { type: "null" } and `NOT NULL` gives { type: "not null" }, + // so testing it for truthiness marked an explicitly nullable + // column as NOT NULL. Only an omitted marker is undefined. + if (d.nullable && d.nullable.type !== "null") { + field.notNull = true; + } field.primary = false; if (d.primary_key) field.primary = true; field.default = ""; diff --git a/src/utils/importSQL/postgres.js b/src/utils/importSQL/postgres.js index ddee8b90b..a9df8db74 100644 --- a/src/utils/importSQL/postgres.js +++ b/src/utils/importSQL/postgres.js @@ -68,7 +68,13 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) { field.increment = false; if (d.auto_increment) field.increment = true; field.notNull = false; - if (d.nullable) field.notNull = true; + // `nullable` is a node for BOTH markers: `NULL` gives + // { type: "null" } and `NOT NULL` gives { type: "not null" }, + // so testing it for truthiness marked an explicitly nullable + // column as NOT NULL. Only an omitted marker is undefined. + if (d.nullable && d.nullable.type !== "null") { + field.notNull = true; + } field.primary = false; if (d.primary_key) field.primary = true; field.default = ""; diff --git a/src/utils/importSQL/sqlite.js b/src/utils/importSQL/sqlite.js index 51b4421ac..f6ce1dae0 100644 --- a/src/utils/importSQL/sqlite.js +++ b/src/utils/importSQL/sqlite.js @@ -131,7 +131,13 @@ export function fromSQLite(ast, diagramDb = DB.GENERIC) { field.increment = false; if (d.auto_increment) field.increment = true; field.notNull = false; - if (d.nullable) field.notNull = true; + // `nullable` is a node for BOTH markers: `NULL` gives + // { type: "null" } and `NOT NULL` gives { type: "not null" }, + // so testing it for truthiness marked an explicitly nullable + // column as NOT NULL. Only an omitted marker is undefined. + if (d.nullable && d.nullable.type !== "null") { + field.notNull = true; + } field.primary = false; if (d.primary_key) field.primary = true; field.default = "";