Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change condition to treat tinyint as boolean #573

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ function mixinDiscovery(MySQL, mysql) {
}
return 'Binary';
case 'TINYINT':
// treat TINYINT(1) as boolean as it is aliased as BOOL and BOOLEAN in mysql
if (!options.treatTINYINT1AsTinyInt && columnType === 'tinyint(1)') {
// treat TINYINT as boolean as it is aliased as BOOL and BOOLEAN in mysql
if (!options.treatTINYINT1AsTinyInt && columnType.includes('tinyint')) {
return 'Boolean';
}
case 'SMALLINT':
Expand Down
6 changes: 5 additions & 1 deletion test/mysql.discover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ describe('Discover and build models', function() {
context('with flag treatTINYINT1AsTinyInt = false', function() {
let models, schema;
before(discoverAndBuildModels);

it('handles CHAR(1) as Boolean', function() {
assert(schema.properties.enabled);
assert.strictEqual(schema.properties.enabled.type, Boolean);
Expand Down Expand Up @@ -526,6 +525,11 @@ describe('Discover and build models', function() {
assert.strictEqual(schema.properties.active.type, Boolean);
});

it('handles TINYINT as Boolean', function() {
assert(schema.properties.archived);
assert.strictEqual(schema.properties.archived.type, Boolean);
});

function discoverAndBuildModels(done) {
db.discoverAndBuildModels('INVENTORY', {
owner: 'STRONGLOOP',
Expand Down
1 change: 1 addition & 0 deletions test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ CREATE TABLE `INVENTORY` (
`AVAILABLE` int(11) DEFAULT NULL,
`TOTAL` int(11) DEFAULT NULL,
`ACTIVE` BOOLEAN DEFAULT TRUE,
`ARCHIVED` TINYINT DEFAULT 1,
`DISABLED` BIT(1) DEFAULT 0,
`ENABLED` CHAR(1) DEFAULT 'Y',
PRIMARY KEY (`PRODUCT_ID`,`LOCATION_ID`),
Expand Down