masterrecord 0.3.68 → 1.0.0
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/.claude/settings.local.json +3 -1
- package/CHANGES.md +31 -2
- package/Cache/QueryCache.js +10 -4
- package/Cache/RedisQueryCache.js +3 -2
- package/Entity/entityModel.js +1 -1
- package/Entity/entityModelBuilder.js +2 -2
- package/Entity/entityTrackerModel.js +3 -3
- package/Entity/fieldTransformer.js +1 -1
- package/FOREIGN_KEY_STRING_FIX.md +2 -2
- package/MasterRecord.js +6 -43
- package/Migrations/cli.js +44 -113
- package/Migrations/dependencyGraph.js +1 -1
- package/Migrations/migrationMySQLQuery.js +1 -1
- package/Migrations/migrationPostgresQuery.js +1 -1
- package/Migrations/migrationSQLiteQuery.js +1 -1
- package/Migrations/migrationTemplate.js +8 -39
- package/Migrations/migrations.js +16 -14
- package/Migrations/pathUtils.js +2 -5
- package/Migrations/pathUtils.test.js +33 -49
- package/Migrations/schema.js +52 -89
- package/QueryLanguage/queryMethods.js +4 -4
- package/QueryLanguage/queryParameters.js +1 -1
- package/QueryLanguage/queryScript.js +4 -3
- package/SQLLiteEngine.js +26 -7
- package/Tools.js +10 -8
- package/context.js +43 -42
- package/deleteManager.js +2 -2
- package/docs/MIGRATIONS_GUIDE.md +237 -532
- package/docs/POSTGRESQL_SETUP.md +4 -4
- package/docs/QUERY_CACHING_GUIDE.md +8 -7
- package/eslint.config.js +40 -0
- package/insertManager.js +28 -20
- package/mySQLConnect.js +2 -2
- package/mySQLEngine.js +26 -6
- package/package.json +34 -5
- package/postgresEngine.js +29 -8
- package/postgresSyncConnect.js +5 -3
- package/prettier.config.js +22 -0
- package/readme.md +35 -27
- package/test/context-errors.test.js +43 -0
- package/test/esm-imports.test.js +110 -0
- package/test/fixtures/new-setter-large-string/config/environments/env.newsetter.json +1 -0
- package/test/fixtures/new-setter-large-string/db/newsettercontext.sqlite +0 -0
- package/test/fixtures/sqlite-lifecycle/config/environments/env.test.json +1 -0
- package/test/fixtures/sqlite-lifecycle/db/lifecyclecontext.sqlite +0 -0
- package/test/migration-template.test.js +47 -0
- package/test/new-setter-large-string.test.js +191 -0
- package/test/pool-key.test.js +43 -0
- package/test/sqlite-lifecycle.test.js +76 -0
- package/.eslintrc.js +0 -290
- package/.prettierrc.js +0 -109
- package/test/anyCommaStringTest.js +0 -237
- package/test/anyMethodTest.js +0 -176
- package/test/attachDetached.test.js +0 -303
- package/test/bulk-operations-test.js +0 -235
- package/test/cache-toObject-test.js +0 -105
- package/test/cacheIntegration.test.js +0 -319
- package/test/config-glob-pattern-test.js +0 -232
- package/test/double-where-bug-test.js +0 -71
- package/test/ensure-ready-test.js +0 -251
- package/test/entity-deduplication-test.js +0 -174
- package/test/entity-methods-test.js +0 -269
- package/test/findByIdTest.js +0 -227
- package/test/foreign-key-string-value-test.js +0 -406
- package/test/global-model-registry-test.js +0 -538
- package/test/id-setting-validation.js +0 -202
- package/test/includesFeatureTest.js +0 -183
- package/test/includesTransformTest.js +0 -110
- package/test/index-bug-fix-test.js +0 -188
- package/test/insert-return-test.js +0 -39
- package/test/lifecycle-hooks-test.js +0 -258
- package/test/multiContextCache.test.js +0 -230
- package/test/new-entity-migration-test.js +0 -162
- package/test/newMethodTest.js +0 -330
- package/test/newMethodUnitTest.js +0 -320
- package/test/optInCache.test.js +0 -221
- package/test/parameterizedPlaceholderTest.js +0 -159
- package/test/pool-registry-test.js +0 -303
- package/test/post-insert-tracking-test.js +0 -258
- package/test/postgresEngineTest.js +0 -463
- package/test/postgresIntegrationTest.js +0 -381
- package/test/promise-detection-test.js +0 -290
- package/test/qa-context-pattern-test.js +0 -319
- package/test/query-helpers-test.js +0 -258
- package/test/query-isolation-test.js +0 -59
- package/test/queryCache.test.js +0 -148
- package/test/securityTest.js +0 -268
- package/test/seed-data-test.js +0 -212
- package/test/seed-deduplication-test.js +0 -313
- package/test/seed-features-integration-test.js +0 -418
- package/test/seed-migration-template-test.js +0 -220
- package/test/singleDollarPlaceholderTest.js +0 -238
- package/test/tablePrefixTest.js +0 -100
- package/test/transformerTest.js +0 -287
- package/test/v0.3.34-bug-fixes-test.js +0 -428
- package/test/validation-test.js +0 -302
- package/test/whereChainingTest.js +0 -88
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
// https://channel9.msdn.com/Blogs/EF/Migrations-Under-the-Hood
|
|
4
|
-
// version 0.0.
|
|
2
|
+
// version 0.0.4
|
|
3
|
+
|
|
4
|
+
import os from 'node:os';
|
|
5
5
|
|
|
6
|
-
const os = require('os');
|
|
7
6
|
class MigrationTemplate {
|
|
8
7
|
|
|
9
8
|
constructor(name) {
|
|
@@ -14,17 +13,10 @@ class MigrationTemplate {
|
|
|
14
13
|
#down = ''
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
|
-
* Render the migration file source.
|
|
18
|
-
*
|
|
19
|
-
* @param {'esm'|'cjs'} [moduleType='cjs'] - Module type of the host project.
|
|
20
|
-
* When 'esm' the file is emitted with ESM syntax so it can be loaded in
|
|
21
|
-
* a `"type": "module"` project. When 'cjs' (default) it's emitted with
|
|
22
|
-
* CJS syntax for backward compatibility with existing projects.
|
|
16
|
+
* Render the migration file source (ESM only).
|
|
23
17
|
*/
|
|
24
|
-
get(
|
|
25
|
-
|
|
26
|
-
return `
|
|
27
|
-
import masterrecord from 'masterrecord';
|
|
18
|
+
get(){
|
|
19
|
+
return `import masterrecord from 'masterrecord';
|
|
28
20
|
|
|
29
21
|
class ${this.name} extends masterrecord.schema {
|
|
30
22
|
constructor(context){
|
|
@@ -42,30 +34,7 @@ class ${this.name} extends masterrecord.schema {
|
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
36
|
export default ${this.name};
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return `
|
|
49
|
-
|
|
50
|
-
var masterrecord = require('masterrecord');
|
|
51
|
-
|
|
52
|
-
class ${this.name} extends masterrecord.schema {
|
|
53
|
-
constructor(context){
|
|
54
|
-
super(context);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async up(table){
|
|
58
|
-
await this.init(table);
|
|
59
|
-
${this.#up}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async down(table){
|
|
63
|
-
await this.init(table);
|
|
64
|
-
${this.#down}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
module.exports = ${this.name};
|
|
68
|
-
`
|
|
37
|
+
`;
|
|
69
38
|
}
|
|
70
39
|
|
|
71
40
|
alterColumn(type, name, parent){
|
|
@@ -329,5 +298,5 @@ module.exports = ${this.name};
|
|
|
329
298
|
|
|
330
299
|
}
|
|
331
300
|
|
|
332
|
-
|
|
301
|
+
export default MigrationTemplate;
|
|
333
302
|
|
package/Migrations/migrations.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
// version 0.0.
|
|
1
|
+
// version 0.0.11
|
|
2
2
|
// learn more about seeding info - https://www.pauric.blog/Database-Updates-and-Migrations-with-Entity-Framework/
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import * as diff from 'deep-object-diff';
|
|
8
|
+
import { globSync } from 'glob';
|
|
9
|
+
import MigrationTemplate from './migrationTemplate.js';
|
|
10
|
+
import { resolveMigrationsDirectory } from './pathUtils.js';
|
|
10
11
|
|
|
11
12
|
// https://blog.tekspace.io/code-first-multiple-db-context-migration/
|
|
12
13
|
|
|
@@ -357,7 +358,7 @@ class Migrations{
|
|
|
357
358
|
|
|
358
359
|
|
|
359
360
|
findContextFile(executedLocation, contextFileName){
|
|
360
|
-
var files =
|
|
361
|
+
var files = globSync(`**/*${contextFileName}.js`, {
|
|
361
362
|
cwd: executedLocation,
|
|
362
363
|
dot: true,
|
|
363
364
|
windowsPathsNoEscape: true
|
|
@@ -366,8 +367,8 @@ class Migrations{
|
|
|
366
367
|
return file;
|
|
367
368
|
}
|
|
368
369
|
|
|
369
|
-
findContext(executedLocation, contextFileName){
|
|
370
|
-
var files =
|
|
370
|
+
async findContext(executedLocation, contextFileName){
|
|
371
|
+
var files = globSync(`**/*${contextFileName}.js`, {
|
|
371
372
|
cwd: executedLocation,
|
|
372
373
|
dot: true,
|
|
373
374
|
windowsPathsNoEscape: true
|
|
@@ -376,7 +377,8 @@ class Migrations{
|
|
|
376
377
|
if(!file){
|
|
377
378
|
return null;
|
|
378
379
|
}
|
|
379
|
-
|
|
380
|
+
const mod = await import(pathToFileURL(file).href);
|
|
381
|
+
const context = (mod && mod.default !== undefined) ? mod.default : mod;
|
|
380
382
|
return {
|
|
381
383
|
context : context,
|
|
382
384
|
fileLocation : file
|
|
@@ -511,7 +513,7 @@ class Migrations{
|
|
|
511
513
|
return false;
|
|
512
514
|
}
|
|
513
515
|
|
|
514
|
-
template(name, oldSchema, newSchema, newSeedData = {}, seedConfig = {}, currentEnv = null
|
|
516
|
+
template(name, oldSchema, newSchema, newSeedData = {}, seedConfig = {}, currentEnv = null){
|
|
515
517
|
var MT = new MigrationTemplate(name);
|
|
516
518
|
// Determine current environment if not provided
|
|
517
519
|
if (!currentEnv) {
|
|
@@ -578,9 +580,9 @@ class Migrations{
|
|
|
578
580
|
|
|
579
581
|
});
|
|
580
582
|
|
|
581
|
-
return MT.get(
|
|
583
|
+
return MT.get();
|
|
582
584
|
}
|
|
583
585
|
|
|
584
586
|
}
|
|
585
587
|
|
|
586
|
-
|
|
588
|
+
export default Migrations;
|
package/Migrations/pathUtils.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Handles path resolution to prevent duplicate db/migrations in paths
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import path from 'node:path';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Resolve migrations directory, avoiding duplicate db/migrations paths
|
|
@@ -70,7 +70,4 @@ function isInMigrationsDirectory(filePath) {
|
|
|
70
70
|
return normalized.includes('/db/migrations') || normalized.includes('\\db\\migrations');
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
resolveMigrationsDirectory,
|
|
75
|
-
isInMigrationsDirectory
|
|
76
|
-
};
|
|
73
|
+
export { resolveMigrationsDirectory, isInMigrationsDirectory };
|
|
@@ -1,53 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for pathUtils.js - Path resolution for migrations
|
|
3
|
-
*
|
|
4
|
-
* Run with: node pathUtils.test.js
|
|
5
3
|
*/
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
'isInMigrationsDirectory should return true for path with db/migrations');
|
|
41
|
-
|
|
42
|
-
// Test 5: isInMigrationsDirectory - false case
|
|
43
|
-
const test5 = isInMigrationsDirectory('/app/models/Context.js');
|
|
44
|
-
assert(test5 === false,
|
|
45
|
-
'isInMigrationsDirectory should return false for path without db/migrations');
|
|
46
|
-
|
|
47
|
-
// Test 6: Windows path with backslashes
|
|
48
|
-
const test6Windows = '/app\\models\\db\\migrations\\Context.js'.replace(/\\/g, path.sep);
|
|
49
|
-
const result6 = isInMigrationsDirectory(test6Windows);
|
|
50
|
-
assert(result6 === true,
|
|
51
|
-
'isInMigrationsDirectory should handle Windows paths with backslashes');
|
|
52
|
-
|
|
53
|
-
console.log('\n✅ All tests passed!\n');
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { test } from 'node:test';
|
|
7
|
+
import assert from 'node:assert/strict';
|
|
8
|
+
import { resolveMigrationsDirectory, isInMigrationsDirectory } from './pathUtils.js';
|
|
9
|
+
|
|
10
|
+
test('resolveMigrationsDirectory: context NOT in migrations folder', () => {
|
|
11
|
+
const result = resolveMigrationsDirectory('/app/models/Context.js');
|
|
12
|
+
const expected = path.join('/app/models', 'db', 'migrations');
|
|
13
|
+
assert.equal(result, expected);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('resolveMigrationsDirectory: context already in migrations folder', () => {
|
|
17
|
+
const result = resolveMigrationsDirectory('/app/models/db/migrations/Context.js');
|
|
18
|
+
assert.equal(result, '/app/models/db/migrations');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('resolveMigrationsDirectory: context in nested migrations folder', () => {
|
|
22
|
+
const result = resolveMigrationsDirectory('/components/qa/app/models/db/migrations/qaContext.js');
|
|
23
|
+
assert.equal(result, '/components/qa/app/models/db/migrations');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('isInMigrationsDirectory: true for path with db/migrations', () => {
|
|
27
|
+
assert.equal(isInMigrationsDirectory('/app/models/db/migrations/Context.js'), true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('isInMigrationsDirectory: false for path without db/migrations', () => {
|
|
31
|
+
assert.equal(isInMigrationsDirectory('/app/models/Context.js'), false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('isInMigrationsDirectory: handles Windows paths', () => {
|
|
35
|
+
const winPath = '/app\\models\\db\\migrations\\Context.js'.replace(/\\/g, path.sep);
|
|
36
|
+
assert.equal(isInMigrationsDirectory(winPath), true);
|
|
37
|
+
});
|