Compare commits

..

42 Commits

Author SHA1 Message Date
renovate[bot] 6198eab5ad chore: update dependency sinon to v20
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-03-31 15:43:11 -04:00
renovate[bot] a4db93762a chore: update dependency sinon to ^19.0.5
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-03-25 18:39:45 -04:00
renovate[bot] 2a4078b407 chore: update dependency sinon to ^19.0.4
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-03-19 20:11:38 -04:00
dhmlau 746bdf49b7 7.1.1
* chore: update dependency loopback-datasource-juggler to ^5.1.6 (renovate[bot])
 * chore: update dependency loopback-connector to ^6.2.2 (renovate[bot])
 * chore: update dependency @commitlint/config-conventional to ^19.8.0 (renovate[bot])
2025-03-18 09:45:26 -04:00
renovate[bot] 82f9c3da42 chore: update dependency loopback-datasource-juggler to ^5.1.6
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-03-17 20:25:40 -04:00
renovate[bot] f8a4ac4e0d chore: update dependency loopback-connector to ^6.2.2
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-03-17 14:41:16 -04:00
renovate[bot] 53724ad430 chore: update dependency @commitlint/config-conventional to ^19.8.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-03-07 20:58:20 -05:00
dhmlau ecb86079cb 7.1.0
* chore: update dependency loopback-datasource-juggler to ^5.1.5 (renovate[bot])
 * chore: update dependency loopback-connector to ^6.2.1 (renovate[bot])
 * chore: update dependency @commitlint/config-conventional to ^19.7.1 (renovate[bot])
 * chore: update dependency loopback-connector to ^6.2.0 (renovate[bot])
 * feat: query to fetch unique columns (Muhammad Aaqil)
 * chore: update dependency mocha to ^11.1.0 (renovate[bot])
 * chore: update dependency debug to ^4.4.0 (renovate[bot])
2025-02-12 10:28:13 -05:00
renovate[bot] 516244148e chore: update dependency loopback-datasource-juggler to ^5.1.5
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-02-11 21:52:57 -05:00
renovate[bot] ca61167e61 chore: update dependency loopback-connector to ^6.2.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-02-10 14:15:34 -05:00
renovate[bot] 908d47b801 chore: update dependency @commitlint/config-conventional to ^19.7.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-02-03 13:03:43 -05:00
renovate[bot] fc43922f3b chore: update dependency loopback-connector to ^6.2.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-02-03 13:03:27 -05:00
Muhammad Aaqil 2386245e15 feat: query to fetch unique columns
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
2025-02-03 10:05:36 +05:30
renovate[bot] 3596be1fa8 chore: update dependency mocha to ^11.1.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-01-22 13:12:28 -05:00
renovate[bot] 83a19eac6f chore: update dependency debug to ^4.4.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-12-11 13:36:39 -05:00
dhmlau d4a39f7ad2 7.0.17
* chore: update dependency loopback-datasource-juggler to ^5.1.3 (renovate[bot])
 * chore: update dependency loopback-connector to ^6.1.12 (renovate[bot])
 * chore: update dependency mocha to v11 (renovate[bot])
 * chore: update dependency @commitlint/config-conventional to ^19.6.0 (renovate[bot])
2024-12-05 12:57:05 -05:00
renovate[bot] 561474c2d2 chore: update dependency loopback-datasource-juggler to ^5.1.3
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-12-05 12:56:06 -05:00
renovate[bot] 41147d3cc9 chore: update dependency loopback-connector to ^6.1.12
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-12-04 13:22:55 -05:00
renovate[bot] db42cf6946 chore: update dependency mocha to v11
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-12-04 08:20:13 -05:00
renovate[bot] 8094eceabc chore: update dependency @commitlint/config-conventional to ^19.6.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-26 11:30:03 -05:00
dhmlau 4c4ddb8ea5 7.0.16
* chore: update dependency loopback-connector to ^6.1.11 (renovate[bot])
 * chore: update dependency loopback-datasource-juggler to ^5.1.2 (renovate[bot])
 * chore: update dependency mocha to ^10.8.2 (renovate[bot])
 * chore: update dependency loopback-connector to ^6.1.10 (renovate[bot])
2024-11-12 08:40:56 -05:00
renovate[bot] f26e5693e1 chore: update dependency loopback-connector to ^6.1.11
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-12 08:40:02 -05:00
renovate[bot] 510e3ac983 chore: update dependency loopback-datasource-juggler to ^5.1.2
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-11 13:40:34 -05:00
renovate[bot] 814c13cf1d chore: update dependency mocha to ^10.8.2
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-01 16:08:31 -04:00
renovate[bot] 9f21dee283 chore: update dependency loopback-connector to ^6.1.10
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-11 10:07:46 -04:00
dhmlau 68a4eb7326 7.0.15
* chore: update dependency loopback-datasource-juggler to ^5.1.1 (renovate[bot])
 * chore: update dependency sinon to v19 (renovate[bot])
 * chore: update dependency ubuntu to v24 (renovate[bot])
 * chore: update dependency eslint to ^8.57.1 (renovate[bot])
 * chore: update dependency sinon to ^18.0.1 (renovate[bot])
 * chore: update dependency @commitlint/config-conventional to ^19.5.0 (renovate[bot])
2024-10-11 10:05:17 -04:00
renovate[bot] ce4262f227 chore: update dependency loopback-datasource-juggler to ^5.1.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-11 09:36:10 -04:00
renovate[bot] 28d41b5f84 chore: update dependency sinon to v19
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-03 10:58:03 -04:00
renovate[bot] d6fa334a17 chore: update dependency ubuntu to v24
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-03 10:52:47 -04:00
renovate[bot] ee3266732e chore: update dependency eslint to ^8.57.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-24 09:52:23 -04:00
renovate[bot] 412dac918c chore: update dependency sinon to ^18.0.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-15 03:48:21 +00:00
renovate[bot] 01337c29d8 chore: update dependency @commitlint/config-conventional to ^19.5.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-14 22:22:09 -04:00
dhmlau 3350462f92 7.0.14
* chore: update dependency loopback-datasource-juggler to ^5.1.0 (renovate[bot])
 * chore: update dependency loopback-connector to ^6.1.9 (renovate[bot])
 * chore: update dependency debug to ^4.3.7 (renovate[bot])
 * fix: enable migration for enum property (Muhammad Aaqil)
 * fix: change condition to treat tinyint as boolean (Muhammad Aaqil)
 * chore: update dependency async to ^3.2.6 (renovate[bot])
 * chore: update dependency @commitlint/config-conventional to ^19.4.1 (renovate[bot])
 * fix: mark primary key auto-increment only if column type is TINYINT SMALLINT MEDIUMINT INT BIGINT (Muhammad Aaqil)
 * chore: update dependency loopback-connector to ^6.1.8 (renovate[bot])
2024-09-09 12:52:32 -04:00
renovate[bot] d352d607c6 chore: update dependency loopback-datasource-juggler to ^5.1.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-09 12:50:44 -04:00
renovate[bot] 8a3a06d288 chore: update dependency loopback-connector to ^6.1.9
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-09 10:42:23 -04:00
renovate[bot] 027d8904be chore: update dependency debug to ^4.3.7
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-09 10:17:54 -04:00
Muhammad Aaqil aa62346c40 fix: enable migration for enum property
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
2024-09-01 20:32:02 +05:00
Muhammad Aaqil 8812d51862 fix: change condition to treat tinyint as boolean
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
2024-09-01 20:31:07 +05:00
renovate[bot] b057c20fe2 chore: update dependency async to ^3.2.6
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-29 22:22:46 -04:00
renovate[bot] 819b32eeda chore: update dependency @commitlint/config-conventional to ^19.4.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-29 22:22:36 -04:00
Muhammad Aaqil b657e73ede fix: mark primary key auto-increment only if column type is TINYINT SMALLINT MEDIUMINT INT BIGINT
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
2024-08-14 14:50:52 -04:00
renovate[bot] b0a5ccc677 chore: update dependency loopback-connector to ^6.1.8
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-14 14:48:55 -04:00
9 changed files with 774 additions and 1041 deletions

View File

@ -8,7 +8,7 @@ on:
jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
env:
MYSQL_HOST: '127.0.0.1'
MYSQL_USER: myUser

View File

@ -1,3 +1,93 @@
2025-03-18, Version 7.1.1
=========================
* chore: update dependency loopback-datasource-juggler to ^5.1.6 (renovate[bot])
* chore: update dependency loopback-connector to ^6.2.2 (renovate[bot])
* chore: update dependency @commitlint/config-conventional to ^19.8.0 (renovate[bot])
2025-02-12, Version 7.1.0
=========================
* chore: update dependency loopback-datasource-juggler to ^5.1.5 (renovate[bot])
* chore: update dependency loopback-connector to ^6.2.1 (renovate[bot])
* chore: update dependency @commitlint/config-conventional to ^19.7.1 (renovate[bot])
* chore: update dependency loopback-connector to ^6.2.0 (renovate[bot])
* feat: query to fetch unique columns (Muhammad Aaqil)
* chore: update dependency mocha to ^11.1.0 (renovate[bot])
* chore: update dependency debug to ^4.4.0 (renovate[bot])
2024-12-05, Version 7.0.17
==========================
* chore: update dependency loopback-datasource-juggler to ^5.1.3 (renovate[bot])
* chore: update dependency loopback-connector to ^6.1.12 (renovate[bot])
* chore: update dependency mocha to v11 (renovate[bot])
* chore: update dependency @commitlint/config-conventional to ^19.6.0 (renovate[bot])
2024-11-12, Version 7.0.16
==========================
* chore: update dependency loopback-connector to ^6.1.11 (renovate[bot])
* chore: update dependency loopback-datasource-juggler to ^5.1.2 (renovate[bot])
* chore: update dependency mocha to ^10.8.2 (renovate[bot])
* chore: update dependency loopback-connector to ^6.1.10 (renovate[bot])
2024-10-11, Version 7.0.15
==========================
* chore: update dependency loopback-datasource-juggler to ^5.1.1 (renovate[bot])
* chore: update dependency sinon to v19 (renovate[bot])
* chore: update dependency ubuntu to v24 (renovate[bot])
* chore: update dependency eslint to ^8.57.1 (renovate[bot])
* chore: update dependency sinon to ^18.0.1 (renovate[bot])
* chore: update dependency @commitlint/config-conventional to ^19.5.0 (renovate[bot])
2024-09-09, Version 7.0.14
==========================
* chore: update dependency loopback-datasource-juggler to ^5.1.0 (renovate[bot])
* chore: update dependency loopback-connector to ^6.1.9 (renovate[bot])
* chore: update dependency debug to ^4.3.7 (renovate[bot])
* fix: enable migration for enum property (Muhammad Aaqil)
* fix: change condition to treat tinyint as boolean (Muhammad Aaqil)
* chore: update dependency async to ^3.2.6 (renovate[bot])
* chore: update dependency @commitlint/config-conventional to ^19.4.1 (renovate[bot])
* fix: mark primary key auto-increment only if column type is TINYINT SMALLINT MEDIUMINT INT BIGINT (Muhammad Aaqil)
* chore: update dependency loopback-connector to ^6.1.8 (renovate[bot])
2024-08-12, Version 7.0.13
==========================

View File

@ -301,6 +301,29 @@ function mixinDiscovery(MySQL, mysql) {
return sql;
};
/**
* Discover unique keys for a given table
* @param {String} table The table name
* @param {Object} options The options for discovery
*/
/*!
* Retrieves a list of column names that have unique key index
* @param schema
* @param table
* @returns {string}
*/
MySQL.prototype.buildQueryUniqueKeys = function(schema, table) {
const sql = 'SELECT Column_name AS "columnName",' +
' table_schema AS "owner",' +
' table_name AS "tableName"' +
' FROM Information_schema.statistics' +
' WHERE Table_schema = ' + mysql.escape(schema) +
' AND Table_name = ' + mysql.escape(table) +
' AND Non_unique = 0 AND Index_name <> \'PRIMARY\';';
return sql;
};
/**
* Discover foreign keys that reference to the primary key of this table
* @param {String} table The table name
@ -358,8 +381,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':

View File

@ -628,7 +628,13 @@ function mixinMigration(MySQL, mysql) {
if (pks.length === 1) {
const idName = this.idName(model);
const idProp = this.getModelDefinition(model).properties[idName];
if (idProp.generated) {
const idColumnType = this.columnDataType(model, idName);
if (idProp.generated && (
idColumnType === 'TINYINT' ||
idColumnType === 'SMALLINT' ||
idColumnType === 'MEDIUMINT' ||
idColumnType === 'INT' ||
idColumnType === 'BIGINT')) {
sql.push(self.columnEscaped(model, idName) + ' ' +
self.buildColumnDefinition(model, idName) + ' AUTO_INCREMENT PRIMARY KEY');
} else {
@ -764,10 +770,21 @@ function mixinMigration(MySQL, mysql) {
const colLength = columnMetadata && columnMetadata.dataLength || prop.length || prop.limit;
const colPrecision = columnMetadata && columnMetadata.dataPrecision;
const colScale = columnMetadata && columnMetadata.dataScale;
let enumList = '';
if (colType && colType === 'ENUM') {
if (prop.jsonSchema && prop.jsonSchema.enum) {
prop.jsonSchema.enum.forEach(item => {
enumList += `'${item}',`;
});
// remove trailing comma
enumList = enumList.substring(0, enumList.length - 1);
}
}
// info on setting column specific properties
// i.e dataLength, dataPrecision, dataScale
// https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html
if (colType) {
if (colType === 'ENUM') return colType + '(' + enumList + ')';
if (colLength) return colType + '(' + colLength + ')';
if (colPrecision && colScale) return colType + '(' + colPrecision + ',' + colScale + ')';
if (colPrecision) return colType + '(' + colPrecision + ')';

1624
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "loopback-connector-mysql",
"version": "7.0.13",
"version": "7.1.1",
"description": "MySQL connector for loopback-datasource-juggler",
"engines": {
"node": ">=18"
@ -21,23 +21,23 @@
"setup.sh"
],
"dependencies": {
"async": "^3.2.5",
"debug": "^4.3.6",
"async": "^3.2.6",
"debug": "^4.4.0",
"lodash": "^4.17.21",
"loopback-connector": "^6.1.7",
"loopback-connector": "^6.2.2",
"mysql2": "^3.6.3",
"patch-package": "^8.0.0",
"strong-globalize": "^6.0.6"
},
"devDependencies": {
"@commitlint/config-conventional": "^19.2.2",
"eslint": "^8.57.0",
"@commitlint/config-conventional": "^19.8.0",
"eslint": "^8.57.1",
"eslint-config-loopback": "^13.1.0",
"loopback-datasource-juggler": "^5.0.12",
"mocha": "^10.7.3",
"loopback-datasource-juggler": "^5.1.6",
"mocha": "^11.1.0",
"rc": "^1.2.8",
"should": "^13.2.3",
"sinon": "^18.0.0"
"sinon": "^20.0.0"
},
"repository": {
"type": "git",

View File

@ -85,6 +85,13 @@ describe('migrations', function() {
Key: '',
Default: null,
Extra: ''},
typings: {
Field: 'typings',
Type: "enum('A','B')",
Null: 'YES',
Key: '',
Default: null,
Extra: ''},
});
done();
});
@ -548,9 +555,10 @@ function setup(done) {
require('./init.js');
db = global.getSchema();
const customType = db.EnumFactory('A', 'B');
UserData = db.define('UserData', {
email: {type: String, null: false, index: true},
typings: {type: customType},
name: String,
bio: Schema.Text,
birthDate: Date,

View File

@ -283,6 +283,21 @@ describe('Discover LDL schema from a table', function() {
});
});
describe('Discover unique properties', function() {
let schema;
before(function(done) {
db.discoverSchema('CUSTOMER', {owner: 'STRONGLOOP'}, function(err, schema_) {
schema = schema_;
done(err);
});
});
it('should validate unique key for customer', function() {
assert.ok(/STRONGLOOP/i.test(schema.options.mysql.schema));
assert.strictEqual(schema.options.mysql.table, 'CUSTOMER');
assert.strictEqual(schema.properties.email.index.unique, true);
});
});
describe('Discover and handle enum', function() {
let schema;
before(function(done) {
@ -518,7 +533,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);
@ -568,6 +582,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',

View File

@ -39,7 +39,8 @@ CREATE TABLE `CUSTOMER` (
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
ALTER TABLE `CUSTOMER`
ADD COLUMN `email` VARCHAR(100) UNIQUE;
--
-- Dumping data for table `CUSTOMER`
--
@ -80,6 +81,7 @@ CREATE TABLE `INVENTORY` (
`TOTAL` int(11) DEFAULT NULL,
`DETAILS` json 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`),