masterrecord 0.3.19 → 0.3.21
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/migrationTemplate.js +9 -9
- package/context.js +29 -1
- package/package.json +1 -1
|
@@ -14,21 +14,21 @@ class MigrationTemplate {
|
|
|
14
14
|
#down = ''
|
|
15
15
|
|
|
16
16
|
get(){
|
|
17
|
-
return `
|
|
18
|
-
|
|
17
|
+
return `
|
|
18
|
+
|
|
19
19
|
var masterrecord = require('masterrecord');
|
|
20
20
|
|
|
21
|
-
class ${this.name} extends masterrecord.schema {
|
|
21
|
+
class ${this.name} extends masterrecord.schema {
|
|
22
22
|
constructor(context){
|
|
23
23
|
super(context);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
up(table){
|
|
26
|
+
async up(table){
|
|
27
27
|
this.init(table);
|
|
28
28
|
${this.#up}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
down(table){
|
|
31
|
+
async down(table){
|
|
32
32
|
this.init(table);
|
|
33
33
|
${this.#down}
|
|
34
34
|
}
|
|
@@ -47,10 +47,10 @@ module.exports = ${this.name};
|
|
|
47
47
|
}
|
|
48
48
|
createTable(type, name){
|
|
49
49
|
if(type === "up"){
|
|
50
|
-
this.#up += os.EOL + ` this.createTable(table.${name});`
|
|
50
|
+
this.#up += os.EOL + ` await this.createTable(table.${name});`
|
|
51
51
|
}
|
|
52
52
|
else{
|
|
53
|
-
this.#down += os.EOL + ` this.createTable(table.${name});`
|
|
53
|
+
this.#down += os.EOL + ` await this.createTable(table.${name});`
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -66,10 +66,10 @@ module.exports = ${this.name};
|
|
|
66
66
|
|
|
67
67
|
dropTable(type, name){
|
|
68
68
|
if(type === "up"){
|
|
69
|
-
this.#down += os.EOL + ` this.
|
|
69
|
+
this.#down += os.EOL + ` this.dropTable(table.${name});`
|
|
70
70
|
}
|
|
71
71
|
else{
|
|
72
|
-
this.#down += os.EOL + ` this.
|
|
72
|
+
this.#down += os.EOL + ` this.dropTable(table.${name});`
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
package/context.js
CHANGED
|
@@ -452,7 +452,35 @@ class context {
|
|
|
452
452
|
const rel = files[0];
|
|
453
453
|
// Ensure absolute path for require()
|
|
454
454
|
const abs = path.isAbsolute(rel) ? rel : path.resolve(currentRoot, rel);
|
|
455
|
-
|
|
455
|
+
|
|
456
|
+
// Find actual project root by looking for package.json or .git
|
|
457
|
+
// This prevents duplicate paths like "app/models/components/workforce/db/"
|
|
458
|
+
let projectRoot = path.dirname(abs);
|
|
459
|
+
let searchDir = projectRoot;
|
|
460
|
+
let foundProjectRoot = false;
|
|
461
|
+
|
|
462
|
+
// Walk up the directory tree to find package.json or .git
|
|
463
|
+
for (let j = 0; j < MAX_CONFIG_SEARCH_HOPS; j++) {
|
|
464
|
+
const hasPackageJson = fs.existsSync(path.join(searchDir, 'package.json'));
|
|
465
|
+
const hasGit = fs.existsSync(path.join(searchDir, '.git'));
|
|
466
|
+
|
|
467
|
+
if (hasPackageJson || hasGit) {
|
|
468
|
+
projectRoot = searchDir;
|
|
469
|
+
foundProjectRoot = true;
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const parent = path.dirname(searchDir);
|
|
474
|
+
if (parent === searchDir) break; // Reached filesystem root
|
|
475
|
+
searchDir = parent;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Fallback to currentRoot if no project markers found
|
|
479
|
+
if (!foundProjectRoot) {
|
|
480
|
+
projectRoot = currentRoot;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return { file: abs, rootFolder: projectRoot };
|
|
456
484
|
}
|
|
457
485
|
|
|
458
486
|
// Move to parent directory
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
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": {
|