masterrecord 1.27.0 → 1.28.1
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/CHANGES.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# MasterRecord Changelog
|
|
2
2
|
|
|
3
|
+
## v1.28.1 — the package no longer contradicts its own engine requirement
|
|
4
|
+
|
|
5
|
+
- **Fix:** `package.json` declared `engines.node: ">=20.0.0"` while depending on
|
|
6
|
+
`commander@^15`, which itself requires `>=22.12.0`. Every Node 20 consumer got an
|
|
7
|
+
`EBADENGINE` warning on install, and the promise of Node 20 support was not actually
|
|
8
|
+
backed by the dependency tree. Pinned to `commander@^14.0.3`, whose own requirement is
|
|
9
|
+
`>=20` — matching what masterrecord claims. No API changes: the CLI uses only
|
|
10
|
+
`command/option/action/alias/description/version/parse`, stable across both majors.
|
|
11
|
+
|
|
12
|
+
Also validated in this release cycle, against a live PostgreSQL 16.15 server rather than
|
|
13
|
+
SQLite: `update-database-all` (the production deploy path) applying a migration and being
|
|
14
|
+
a no-op on re-run, `migrations-status`, `update-database-down` (transactional since 1.26.0
|
|
15
|
+
— table dropped and history row removed), correct Postgres column types including
|
|
16
|
+
`boolean` and temporal columns as `TEXT`, and the history table carrying `product_version`.
|
|
17
|
+
|
|
18
|
+
## v1.28.0 — `ensureCreated()` actually works on MySQL/Postgres (found by live testing)
|
|
19
|
+
|
|
20
|
+
The first live run of the cross-engine suite, against a real PostgreSQL 16.15 server,
|
|
21
|
+
found that **`ensureCreated()` could never work on MySQL or Postgres when the database did
|
|
22
|
+
not exist** — which is the one case it exists for. The context cannot connect without an
|
|
23
|
+
existing database, so it threw during initialization long before `ensureCreated()` ran. It
|
|
24
|
+
only appeared to work on SQLite, where opening the file creates it.
|
|
25
|
+
|
|
26
|
+
- **Fix:** `exists()` and `create()` now run over an **admin connection** (the `postgres`
|
|
27
|
+
maintenance database; MySQL with no database selected) instead of the context's own
|
|
28
|
+
engine, so they work when the target database is absent — the approach EF's providers
|
|
29
|
+
take. After creating it the context's pool is reopened and the context marked ready, so
|
|
30
|
+
its stale rejected init promise is not re-awaited.
|
|
31
|
+
- **Fix:** `context.database` no longer fails outright when the database is missing; that
|
|
32
|
+
is the state `ensureCreated()` is for. Any other connection error still propagates.
|
|
33
|
+
- Verified end to end on live PostgreSQL 16.15: `CREATE DATABASE` -> `EnsureCreated`
|
|
34
|
+
(schema) -> insert/read -> history + `ProductVersion` -> `baseline()` -> `EnsureDeleted`
|
|
35
|
+
(`pg_terminate_backend` + drop from the maintenance database), with no scratch databases
|
|
36
|
+
or stray tables left behind.
|
|
37
|
+
- The cross-engine suite is safe against a shared server by default — it only creates and
|
|
38
|
+
drops its own `MrEfProbe*` tables. The create/drop-database lifecycle is opt-in with
|
|
39
|
+
`MR_TEST_ALLOW_CREATE_DB=1`.
|
|
40
|
+
|
|
3
41
|
## v1.27.0 — `Migrator.GenerateScript` and `HasPendingModelChanges`: EF's `IMigrator` is now complete
|
|
4
42
|
|
|
5
43
|
1.26.0 moved applying into `Migrator`; this finishes the interface. EF's `IMigrator` is
|
|
@@ -216,12 +216,24 @@ class DatabaseFacade {
|
|
|
216
216
|
return this.historyRepository.getInsertScript(new HistoryRow(migrationId, PRODUCT_VERSION, new Date().toISOString()));
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Wait for the context's connection, but do NOT fail when the database simply
|
|
221
|
+
* does not exist yet — that is precisely the state `ensureCreated()` exists to
|
|
222
|
+
* fix, and on MySQL/Postgres the context cannot connect until the database is
|
|
223
|
+
* there. Existence checks and creation run over an admin connection instead.
|
|
224
|
+
*/
|
|
219
225
|
async _ready() {
|
|
220
226
|
if (this.context && this.context._initPromise) {
|
|
221
|
-
try { await this.context._initPromise; } catch (_) { /*
|
|
227
|
+
try { await this.context._initPromise; } catch (_) { /* reported by the first real query */ }
|
|
222
228
|
}
|
|
223
229
|
if (this.context && typeof this.context._ensureReady === 'function') {
|
|
224
|
-
|
|
230
|
+
try {
|
|
231
|
+
await this.context._ensureReady();
|
|
232
|
+
} catch (err) {
|
|
233
|
+
const msg = String((err && err.message) || '');
|
|
234
|
+
const missing = /does not exist|Unknown database/i.test(msg);
|
|
235
|
+
if (!missing) throw err;
|
|
236
|
+
}
|
|
225
237
|
}
|
|
226
238
|
}
|
|
227
239
|
}
|
|
@@ -239,14 +239,28 @@ class MySqlDatabaseCreator extends RelationalDatabaseCreator {
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
async exists() {
|
|
242
|
-
const rows = await this.
|
|
243
|
-
`SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${
|
|
242
|
+
const rows = await this._adminQuery(
|
|
243
|
+
`SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${assertDatabaseName(this.databaseName)}'`);
|
|
244
244
|
return !!(rows && rows.length);
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
async create() {
|
|
248
248
|
const schema = await this.getSchema();
|
|
249
249
|
await schema._createDatabaseFromConfig();
|
|
250
|
+
await this._reconnect();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Re-open the context's pool now that the database exists, and mark the context
|
|
255
|
+
* ready — its original _initPromise rejected (the database was missing) and
|
|
256
|
+
* _ensureReady() would otherwise keep re-awaiting that stale rejection.
|
|
257
|
+
*/
|
|
258
|
+
async _reconnect() {
|
|
259
|
+
const schema = await this.getSchema();
|
|
260
|
+
if (typeof schema._retryMySQLInit === 'function') {
|
|
261
|
+
await schema._retryMySQLInit();
|
|
262
|
+
this.context._ready = true;
|
|
263
|
+
}
|
|
250
264
|
}
|
|
251
265
|
|
|
252
266
|
async hasTables() {
|
|
@@ -266,7 +280,7 @@ class MySqlDatabaseCreator extends RelationalDatabaseCreator {
|
|
|
266
280
|
await this._adminQuery(`DROP DATABASE IF EXISTS \`${dbName}\``);
|
|
267
281
|
}
|
|
268
282
|
|
|
269
|
-
/** Run a statement on a connection that has no database selected. */
|
|
283
|
+
/** Run a statement on a connection that has no database selected; returns rows. */
|
|
270
284
|
async _adminQuery(sql) {
|
|
271
285
|
const config = this.context._dbConfig || {};
|
|
272
286
|
const { default: MySQLAsyncClient } = await import('../mySQLConnect.js');
|
|
@@ -277,7 +291,9 @@ class MySqlDatabaseCreator extends RelationalDatabaseCreator {
|
|
|
277
291
|
await admin.connect();
|
|
278
292
|
try {
|
|
279
293
|
const pool = admin.getPool();
|
|
280
|
-
if (pool)
|
|
294
|
+
if (!pool) return [];
|
|
295
|
+
const [rows] = await pool.query(sql);
|
|
296
|
+
return Array.isArray(rows) ? rows : [];
|
|
281
297
|
} finally {
|
|
282
298
|
await admin.close();
|
|
283
299
|
}
|
|
@@ -291,8 +307,8 @@ class PostgresDatabaseCreator extends RelationalDatabaseCreator {
|
|
|
291
307
|
}
|
|
292
308
|
|
|
293
309
|
async exists() {
|
|
294
|
-
const rows = await this.
|
|
295
|
-
`SELECT 1 FROM pg_database WHERE datname = '${
|
|
310
|
+
const rows = await this._adminQuery(
|
|
311
|
+
`SELECT 1 FROM pg_database WHERE datname = '${assertDatabaseName(this.databaseName)}'`);
|
|
296
312
|
return !!(rows && rows.length);
|
|
297
313
|
}
|
|
298
314
|
|
|
@@ -301,6 +317,20 @@ class PostgresDatabaseCreator extends RelationalDatabaseCreator {
|
|
|
301
317
|
if (typeof schema._createPostgresDatabaseFromConfig === 'function') {
|
|
302
318
|
await schema._createPostgresDatabaseFromConfig();
|
|
303
319
|
}
|
|
320
|
+
await this._reconnect();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Re-open the context's pool now that the database exists, and mark the context
|
|
325
|
+
* ready — its original _initPromise rejected (the database was missing) and
|
|
326
|
+
* _ensureReady() would otherwise keep re-awaiting that stale rejection.
|
|
327
|
+
*/
|
|
328
|
+
async _reconnect() {
|
|
329
|
+
const schema = await this.getSchema();
|
|
330
|
+
if (typeof schema._retryPostgresInit === 'function') {
|
|
331
|
+
await schema._retryPostgresInit();
|
|
332
|
+
this.context._ready = true;
|
|
333
|
+
}
|
|
304
334
|
}
|
|
305
335
|
|
|
306
336
|
async hasTables() {
|
|
@@ -337,7 +367,8 @@ class PostgresDatabaseCreator extends RelationalDatabaseCreator {
|
|
|
337
367
|
ssl: config.ssl || false,
|
|
338
368
|
});
|
|
339
369
|
try {
|
|
340
|
-
await adminPool.query(sql);
|
|
370
|
+
const r = await adminPool.query(sql);
|
|
371
|
+
return (r && r.rows) ? r.rows : [];
|
|
341
372
|
} finally {
|
|
342
373
|
await adminPool.end();
|
|
343
374
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.1",
|
|
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
|
"type": "module",
|
|
6
6
|
"main": "./MasterRecord.js",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"better-sqlite3": ">=12.6.2 <14",
|
|
89
|
-
"commander": "^
|
|
89
|
+
"commander": "^14.0.3",
|
|
90
90
|
"deep-object-diff": "^1.1.9",
|
|
91
91
|
"glob": "^13.0.6",
|
|
92
92
|
"mysql2": "^3.23.2",
|