Compare commits
53 Commits
Author | SHA1 | Date |
---|---|---|
|
6198eab5ad | |
|
a4db93762a | |
|
2a4078b407 | |
|
746bdf49b7 | |
|
82f9c3da42 | |
|
f8a4ac4e0d | |
|
53724ad430 | |
|
ecb86079cb | |
|
516244148e | |
|
ca61167e61 | |
|
908d47b801 | |
|
fc43922f3b | |
|
2386245e15 | |
|
3596be1fa8 | |
|
83a19eac6f | |
|
d4a39f7ad2 | |
|
561474c2d2 | |
|
41147d3cc9 | |
|
db42cf6946 | |
|
8094eceabc | |
|
4c4ddb8ea5 | |
|
f26e5693e1 | |
|
510e3ac983 | |
|
814c13cf1d | |
|
9f21dee283 | |
|
68a4eb7326 | |
|
ce4262f227 | |
|
28d41b5f84 | |
|
d6fa334a17 | |
|
ee3266732e | |
|
412dac918c | |
|
01337c29d8 | |
|
3350462f92 | |
|
d352d607c6 | |
|
8a3a06d288 | |
|
027d8904be | |
|
aa62346c40 | |
|
8812d51862 | |
|
b057c20fe2 | |
|
819b32eeda | |
|
b657e73ede | |
|
b0a5ccc677 | |
|
fb9c9ca92f | |
|
d1c7d08fa9 | |
|
a4b1e09587 | |
|
c1d337ebb8 | |
|
3c7ea78c4e | |
|
efe6731d92 | |
|
67c1f361bf | |
|
55301a751a | |
|
cf48e4b191 | |
|
0e2ff542c2 | |
|
5f73b68410 |
|
@ -8,7 +8,7 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
env:
|
env:
|
||||||
MYSQL_HOST: '127.0.0.1'
|
MYSQL_HOST: '127.0.0.1'
|
||||||
MYSQL_USER: myUser
|
MYSQL_USER: myUser
|
||||||
|
|
116
CHANGES.md
116
CHANGES.md
|
@ -1,3 +1,119 @@
|
||||||
|
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
|
||||||
|
==========================
|
||||||
|
|
||||||
|
* chore: update dependency loopback-datasource-juggler to ^5.0.12 (renovate[bot])
|
||||||
|
|
||||||
|
* chore: update dependency mocha to ^10.7.3 (renovate[bot])
|
||||||
|
|
||||||
|
* chore: update dependency debug to ^4.3.6 (renovate[bot])
|
||||||
|
|
||||||
|
* chore: update dependency mocha to ^10.7.0 (renovate[bot])
|
||||||
|
|
||||||
|
|
||||||
|
2024-07-04, Version 7.0.12
|
||||||
|
==========================
|
||||||
|
|
||||||
|
* chore: update dependency loopback-datasource-juggler to ^5.0.11 (renovate[bot])
|
||||||
|
|
||||||
|
* chore: update dependency loopback-connector to ^6.1.7 (renovate[bot])
|
||||||
|
|
||||||
|
* chore: update dependency mocha to ^10.6.0 (renovate[bot])
|
||||||
|
|
||||||
|
* chore: update dependency mocha to ^10.5.2 (renovate[bot])
|
||||||
|
|
||||||
|
* chore: update dependency loopback-connector to ^6.1.6 (renovate[bot])
|
||||||
|
|
||||||
|
|
||||||
2024-06-06, Version 7.0.11
|
2024-06-06, Version 7.0.11
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
|
|
@ -301,6 +301,29 @@ function mixinDiscovery(MySQL, mysql) {
|
||||||
return sql;
|
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
|
* Discover foreign keys that reference to the primary key of this table
|
||||||
* @param {String} table The table name
|
* @param {String} table The table name
|
||||||
|
@ -358,8 +381,8 @@ function mixinDiscovery(MySQL, mysql) {
|
||||||
}
|
}
|
||||||
return 'Binary';
|
return 'Binary';
|
||||||
case 'TINYINT':
|
case 'TINYINT':
|
||||||
// treat TINYINT(1) as boolean as it is aliased as BOOL and BOOLEAN in mysql
|
// treat TINYINT as boolean as it is aliased as BOOL and BOOLEAN in mysql
|
||||||
if (!options.treatTINYINT1AsTinyInt && columnType === 'tinyint(1)') {
|
if (!options.treatTINYINT1AsTinyInt && columnType.includes('tinyint')) {
|
||||||
return 'Boolean';
|
return 'Boolean';
|
||||||
}
|
}
|
||||||
case 'SMALLINT':
|
case 'SMALLINT':
|
||||||
|
|
|
@ -628,7 +628,13 @@ function mixinMigration(MySQL, mysql) {
|
||||||
if (pks.length === 1) {
|
if (pks.length === 1) {
|
||||||
const idName = this.idName(model);
|
const idName = this.idName(model);
|
||||||
const idProp = this.getModelDefinition(model).properties[idName];
|
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) + ' ' +
|
sql.push(self.columnEscaped(model, idName) + ' ' +
|
||||||
self.buildColumnDefinition(model, idName) + ' AUTO_INCREMENT PRIMARY KEY');
|
self.buildColumnDefinition(model, idName) + ' AUTO_INCREMENT PRIMARY KEY');
|
||||||
} else {
|
} else {
|
||||||
|
@ -764,10 +770,21 @@ function mixinMigration(MySQL, mysql) {
|
||||||
const colLength = columnMetadata && columnMetadata.dataLength || prop.length || prop.limit;
|
const colLength = columnMetadata && columnMetadata.dataLength || prop.length || prop.limit;
|
||||||
const colPrecision = columnMetadata && columnMetadata.dataPrecision;
|
const colPrecision = columnMetadata && columnMetadata.dataPrecision;
|
||||||
const colScale = columnMetadata && columnMetadata.dataScale;
|
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
|
// info on setting column specific properties
|
||||||
// i.e dataLength, dataPrecision, dataScale
|
// i.e dataLength, dataPrecision, dataScale
|
||||||
// https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html
|
// https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html
|
||||||
if (colType) {
|
if (colType) {
|
||||||
|
if (colType === 'ENUM') return colType + '(' + enumList + ')';
|
||||||
if (colLength) return colType + '(' + colLength + ')';
|
if (colLength) return colType + '(' + colLength + ')';
|
||||||
if (colPrecision && colScale) return colType + '(' + colPrecision + ',' + colScale + ')';
|
if (colPrecision && colScale) return colType + '(' + colPrecision + ',' + colScale + ')';
|
||||||
if (colPrecision) return colType + '(' + colPrecision + ')';
|
if (colPrecision) return colType + '(' + colPrecision + ')';
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "loopback-connector-mysql",
|
"name": "loopback-connector-mysql",
|
||||||
"version": "7.0.11",
|
"version": "7.1.1",
|
||||||
"description": "MySQL connector for loopback-datasource-juggler",
|
"description": "MySQL connector for loopback-datasource-juggler",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
|
@ -21,23 +21,23 @@
|
||||||
"setup.sh"
|
"setup.sh"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^3.2.5",
|
"async": "^3.2.6",
|
||||||
"debug": "^4.3.5",
|
"debug": "^4.4.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"loopback-connector": "^6.1.5",
|
"loopback-connector": "^6.2.2",
|
||||||
"mysql2": "^3.6.3",
|
"mysql2": "^3.6.3",
|
||||||
"patch-package": "^8.0.0",
|
"patch-package": "^8.0.0",
|
||||||
"strong-globalize": "^6.0.6"
|
"strong-globalize": "^6.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/config-conventional": "^19.2.2",
|
"@commitlint/config-conventional": "^19.8.0",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.1",
|
||||||
"eslint-config-loopback": "^13.1.0",
|
"eslint-config-loopback": "^13.1.0",
|
||||||
"loopback-datasource-juggler": "^5.0.10",
|
"loopback-datasource-juggler": "^5.1.6",
|
||||||
"mocha": "^10.4.0",
|
"mocha": "^11.1.0",
|
||||||
"rc": "^1.2.8",
|
"rc": "^1.2.8",
|
||||||
"should": "^13.2.3",
|
"should": "^13.2.3",
|
||||||
"sinon": "^18.0.0"
|
"sinon": "^20.0.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -85,6 +85,13 @@ describe('migrations', function() {
|
||||||
Key: '',
|
Key: '',
|
||||||
Default: null,
|
Default: null,
|
||||||
Extra: ''},
|
Extra: ''},
|
||||||
|
typings: {
|
||||||
|
Field: 'typings',
|
||||||
|
Type: "enum('A','B')",
|
||||||
|
Null: 'YES',
|
||||||
|
Key: '',
|
||||||
|
Default: null,
|
||||||
|
Extra: ''},
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -548,9 +555,10 @@ function setup(done) {
|
||||||
require('./init.js');
|
require('./init.js');
|
||||||
|
|
||||||
db = global.getSchema();
|
db = global.getSchema();
|
||||||
|
const customType = db.EnumFactory('A', 'B');
|
||||||
UserData = db.define('UserData', {
|
UserData = db.define('UserData', {
|
||||||
email: {type: String, null: false, index: true},
|
email: {type: String, null: false, index: true},
|
||||||
|
typings: {type: customType},
|
||||||
name: String,
|
name: String,
|
||||||
bio: Schema.Text,
|
bio: Schema.Text,
|
||||||
birthDate: Date,
|
birthDate: Date,
|
||||||
|
|
|
@ -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() {
|
describe('Discover and handle enum', function() {
|
||||||
let schema;
|
let schema;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
|
@ -518,7 +533,6 @@ describe('Discover and build models', function() {
|
||||||
context('with flag treatTINYINT1AsTinyInt = false', function() {
|
context('with flag treatTINYINT1AsTinyInt = false', function() {
|
||||||
let models, schema;
|
let models, schema;
|
||||||
before(discoverAndBuildModels);
|
before(discoverAndBuildModels);
|
||||||
|
|
||||||
it('handles CHAR(1) as Boolean', function() {
|
it('handles CHAR(1) as Boolean', function() {
|
||||||
assert(schema.properties.enabled);
|
assert(schema.properties.enabled);
|
||||||
assert.strictEqual(schema.properties.enabled.type, Boolean);
|
assert.strictEqual(schema.properties.enabled.type, Boolean);
|
||||||
|
@ -568,6 +582,11 @@ describe('Discover and build models', function() {
|
||||||
assert.strictEqual(schema.properties.active.type, Boolean);
|
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) {
|
function discoverAndBuildModels(done) {
|
||||||
db.discoverAndBuildModels('INVENTORY', {
|
db.discoverAndBuildModels('INVENTORY', {
|
||||||
owner: 'STRONGLOOP',
|
owner: 'STRONGLOOP',
|
||||||
|
|
|
@ -39,7 +39,8 @@ CREATE TABLE `CUSTOMER` (
|
||||||
PRIMARY KEY (`ID`)
|
PRIMARY KEY (`ID`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
ALTER TABLE `CUSTOMER`
|
||||||
|
ADD COLUMN `email` VARCHAR(100) UNIQUE;
|
||||||
--
|
--
|
||||||
-- Dumping data for table `CUSTOMER`
|
-- Dumping data for table `CUSTOMER`
|
||||||
--
|
--
|
||||||
|
@ -80,6 +81,7 @@ CREATE TABLE `INVENTORY` (
|
||||||
`TOTAL` int(11) DEFAULT NULL,
|
`TOTAL` int(11) DEFAULT NULL,
|
||||||
`DETAILS` json DEFAULT NULL,
|
`DETAILS` json DEFAULT NULL,
|
||||||
`ACTIVE` BOOLEAN DEFAULT TRUE,
|
`ACTIVE` BOOLEAN DEFAULT TRUE,
|
||||||
|
`ARCHIVED` TINYINT DEFAULT 1,
|
||||||
`DISABLED` BIT(1) DEFAULT 0,
|
`DISABLED` BIT(1) DEFAULT 0,
|
||||||
`ENABLED` CHAR(1) DEFAULT 'Y',
|
`ENABLED` CHAR(1) DEFAULT 'Y',
|
||||||
PRIMARY KEY (`PRODUCT_ID`,`LOCATION_ID`),
|
PRIMARY KEY (`PRODUCT_ID`,`LOCATION_ID`),
|
||||||
|
|
Loading…
Reference in New Issue