masterrecord 0.3.40 → 0.3.41
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/cli.js +4 -12
- package/context.js +9 -0
- package/package.json +1 -1
- package/readme.md +14 -0
package/Migrations/cli.js
CHANGED
|
@@ -259,8 +259,11 @@ program.option('-V', 'output the version');
|
|
|
259
259
|
}
|
|
260
260
|
let contextInstance;
|
|
261
261
|
try{
|
|
262
|
+
process.env.MASTERRECORD_SCHEMA_ONLY = '1';
|
|
262
263
|
contextInstance = new ContextCtor();
|
|
264
|
+
delete process.env.MASTERRECORD_SCHEMA_ONLY;
|
|
263
265
|
}catch(err){
|
|
266
|
+
delete process.env.MASTERRECORD_SCHEMA_ONLY;
|
|
264
267
|
console.error(`\n❌ Error - Failed to construct Context from '${contextAbs}'`);
|
|
265
268
|
console.error(`\nThis usually happens when:`);
|
|
266
269
|
console.error(` • Environment configuration is missing or invalid`);
|
|
@@ -291,27 +294,16 @@ program.option('-V', 'output the version');
|
|
|
291
294
|
}
|
|
292
295
|
var migrationDate = Date.now();
|
|
293
296
|
var outputFile = `${migBase}/${migrationDate}_${name}_migration.js`
|
|
294
|
-
fs.writeFile(outputFile, newEntity, 'utf8',
|
|
297
|
+
fs.writeFile(outputFile, newEntity, 'utf8', function (err) {
|
|
295
298
|
if (err) {
|
|
296
299
|
console.log("--- Error running cammand, re-run command add-migration ---- ", err);
|
|
297
|
-
if (contextInstance && typeof contextInstance.close === 'function') {
|
|
298
|
-
await contextInstance.close();
|
|
299
|
-
}
|
|
300
300
|
process.exit(1);
|
|
301
301
|
}
|
|
302
302
|
console.log(`✓ Migration '${name}' created successfully at ${outputFile}`);
|
|
303
|
-
|
|
304
|
-
// Close database connections to prevent hanging
|
|
305
|
-
if (contextInstance && typeof contextInstance.close === 'function') {
|
|
306
|
-
await contextInstance.close();
|
|
307
|
-
}
|
|
308
303
|
process.exit(0);
|
|
309
304
|
});
|
|
310
305
|
}catch (e){
|
|
311
306
|
console.log("Error - Cannot read or find file ", e);
|
|
312
|
-
if (contextInstance && typeof contextInstance.close === 'function') {
|
|
313
|
-
await contextInstance.close();
|
|
314
|
-
}
|
|
315
307
|
process.exit(1);
|
|
316
308
|
}
|
|
317
309
|
});
|
package/context.js
CHANGED
|
@@ -675,6 +675,15 @@ class context {
|
|
|
675
675
|
|
|
676
676
|
const type = String(options.type || '').toLowerCase();
|
|
677
677
|
|
|
678
|
+
// Schema-only mode: CLI commands like add-migration only need entity metadata,
|
|
679
|
+
// not a live database connection. Skip DB initialization entirely.
|
|
680
|
+
if (process.env.MASTERRECORD_SCHEMA_ONLY === '1') {
|
|
681
|
+
this.isSQLite = (type === DB_TYPES.SQLITE || type === DB_TYPES.BETTER_SQLITE3);
|
|
682
|
+
this.isMySQL = (type === DB_TYPES.MYSQL);
|
|
683
|
+
this.isPostgres = (type === DB_TYPES.POSTGRES || type === DB_TYPES.POSTGRESQL);
|
|
684
|
+
return this;
|
|
685
|
+
}
|
|
686
|
+
|
|
678
687
|
// SQLite initialization
|
|
679
688
|
if (type === DB_TYPES.SQLITE || type === DB_TYPES.BETTER_SQLITE3) {
|
|
680
689
|
this.isSQLite = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.41",
|
|
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/readme.md
CHANGED
|
@@ -3369,6 +3369,20 @@ user.name = null; // Error if name is { nullable: false }
|
|
|
3369
3369
|
|
|
3370
3370
|
## Changelog
|
|
3371
3371
|
|
|
3372
|
+
### Version 0.3.41 (2026-02-20) - FIX: add-migration No Longer Creates Unnecessary Database Connections
|
|
3373
|
+
|
|
3374
|
+
#### Bug Fixed: `add-migration` creating real database connections and files
|
|
3375
|
+
- **FIXED**: Running `masterrecord add-migration` would open a real database connection (creating SQLite files on disk, or connecting to MySQL/PostgreSQL) even though it only needs entity schemas and seed data to generate migration files
|
|
3376
|
+
- **Problem**: On production servers, `add-migration` created unwanted `.sqlite3` files and printed misleading "SQLite database closed" messages
|
|
3377
|
+
- **Root Cause**: The context constructor calls `env()` which initializes a full database connection; `add-migration` only needs entity metadata
|
|
3378
|
+
- **Solution**: Added schema-only mode (`MASTERRECORD_SCHEMA_ONLY` env var) that sets database type flags for correct entity registration but skips all database initialization (no file creation, no connections)
|
|
3379
|
+
- **Impact**: `add-migration` is now faster, creates no side effects, and works safely on production servers
|
|
3380
|
+
|
|
3381
|
+
#### Files Modified
|
|
3382
|
+
1. **`Migrations/cli.js`** - Set `MASTERRECORD_SCHEMA_ONLY=1` before context construction, removed unnecessary `close()` calls
|
|
3383
|
+
2. **`context.js`** - Added schema-only mode check in `env()` that returns early after setting type flags
|
|
3384
|
+
3. **`package.json`** - Updated to v0.3.41
|
|
3385
|
+
|
|
3372
3386
|
### Version 0.3.39 (2026-02-09) - CRITICAL BUG FIX: Foreign Key String Values
|
|
3373
3387
|
|
|
3374
3388
|
#### Bug Fixed: Foreign Key Fields Silently Ignoring String Values
|