masterrecord 0.3.45 → 0.3.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Migrations/schema.js +10 -2
- package/mySQLEngine.js +8 -0
- package/package.json +1 -1
- package/postgresEngine.js +8 -0
package/Migrations/schema.js
CHANGED
|
@@ -16,6 +16,7 @@ class schema{
|
|
|
16
16
|
* create the database first, then retry the connection.
|
|
17
17
|
*/
|
|
18
18
|
async _ensureReady(){
|
|
19
|
+
if(this._ready){ return; }
|
|
19
20
|
if(this.context && this.context._initPromise){
|
|
20
21
|
try{
|
|
21
22
|
await this.context._initPromise;
|
|
@@ -35,6 +36,7 @@ class schema{
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
this._ready = true;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/**
|
|
@@ -295,8 +297,12 @@ class schema{
|
|
|
295
297
|
const existingNames = new Set((existing || []).map(c => (c.name || c.COLUMN_NAME))); // both engines map to name
|
|
296
298
|
// Add missing columns only (safe path)
|
|
297
299
|
for (var key in table) {
|
|
298
|
-
|
|
300
|
+
// Skip metadata properties (indexes, __compositeIndexes, __name, etc.)
|
|
301
|
+
if(key === 'indexes' || key.startsWith('__')) continue;
|
|
302
|
+
if(typeof table[key] === 'object' && !Array.isArray(table[key])){
|
|
299
303
|
const col = table[key];
|
|
304
|
+
// Skip if missing name/type (not a valid column definition)
|
|
305
|
+
if(!col.name || !col.type) continue;
|
|
300
306
|
// Skip relationships
|
|
301
307
|
if(col.type === 'hasOne' || col.type === 'hasMany' || col.type === 'hasManyThrough') continue;
|
|
302
308
|
const colName = (col.relationshipType === 'belongsTo' && col.foreignKey) ? col.foreignKey : col.name;
|
|
@@ -335,8 +341,10 @@ class schema{
|
|
|
335
341
|
// Detect modifications (nullable/default/type)
|
|
336
342
|
const desiredCols = [];
|
|
337
343
|
for (var key in table) {
|
|
338
|
-
if(
|
|
344
|
+
if(key === 'indexes' || key.startsWith('__')) continue;
|
|
345
|
+
if(typeof table[key] === 'object' && !Array.isArray(table[key])){
|
|
339
346
|
const col = table[key];
|
|
347
|
+
if(!col.name || !col.type) continue;
|
|
340
348
|
if(col.type === 'hasOne' || col.type === 'hasMany' || col.type === 'hasManyThrough') continue;
|
|
341
349
|
const colName = (col.relationshipType === 'belongsTo' && col.foreignKey) ? col.foreignKey : col.name;
|
|
342
350
|
desiredCols.push({ name: colName, col });
|
package/mySQLEngine.js
CHANGED
|
@@ -798,6 +798,14 @@ class MySQLEngine {
|
|
|
798
798
|
}
|
|
799
799
|
}
|
|
800
800
|
|
|
801
|
+
/**
|
|
802
|
+
* Execute raw SQL (DDL statements like CREATE TABLE, ALTER TABLE, etc.)
|
|
803
|
+
* Used by migration schema for non-parameterized DDL queries.
|
|
804
|
+
*/
|
|
805
|
+
_execute(query) {
|
|
806
|
+
return this._runWithParams(query, []);
|
|
807
|
+
}
|
|
808
|
+
|
|
801
809
|
/**
|
|
802
810
|
* Execute parameterized query with mysql2/promise
|
|
803
811
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.47",
|
|
4
4
|
"description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
|
|
5
5
|
"main": "MasterRecord.js",
|
|
6
6
|
"bin": {
|
package/postgresEngine.js
CHANGED
|
@@ -750,6 +750,14 @@ class postgresEngine {
|
|
|
750
750
|
/**
|
|
751
751
|
* Execute parameterized query with pg library
|
|
752
752
|
*/
|
|
753
|
+
/**
|
|
754
|
+
* Execute raw SQL (DDL statements like CREATE TABLE, ALTER TABLE, etc.)
|
|
755
|
+
* Used by migration schema for non-parameterized DDL queries.
|
|
756
|
+
*/
|
|
757
|
+
_execute(query) {
|
|
758
|
+
return this._runWithParams(query, []);
|
|
759
|
+
}
|
|
760
|
+
|
|
753
761
|
async _runWithParams(query, params = []) {
|
|
754
762
|
try {
|
|
755
763
|
if (process.env.LOG_SQL === 'true' || process.env.NODE_ENV !== 'production') {
|