Skip to content

Commit

Permalink
Fix unsigned data type reading in MSSQL (directus#6058)
Browse files Browse the repository at this point in the history
  • Loading branch information
rijkvanzanten authored Jun 4, 2021
1 parent f2180b1 commit fe6101c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/schema/src/dialects/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ export default class MySQL extends KnexMySQL implements SchemaInspector {
};
}

let dataType = column.data_type.split('(')[0];

/**
* Smooth out a difference between MySQL and MariaDB. MySQL reports the column type as `int
* unsigned`, while MariaDB reports it as `int(11) unsigned`. This would cause the `unsigned` part
* of the type to be dropped in the columnInfo retrieval for MariaDB powered databases.
*/
if (column.data_type.includes('unsigned') && dataType.includes('unsigned') === false) {
dataType += ' unsigned';
}

overview[column.table_name].columns[column.column_name] = {
...column,
default_value: column.extra === 'auto_increment' ? 'AUTO_INCREMENT' : parseDefaultValue(column.default_value),
is_nullable: column.is_nullable === 'YES',
data_type: column.data_type.split('(')[0],
data_type: dataType,
};
}

Expand Down

0 comments on commit fe6101c

Please sign in to comment.