ilana-orm 1.0.0 → 1.0.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/cli/ilana.js +42 -19
- package/orm/MigrationRunner.js +27 -3
- package/package.json +3 -3
package/cli/ilana.js
CHANGED
|
@@ -30,13 +30,24 @@ const defaultConfig = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
// Load configuration and auto-initialize
|
|
33
|
-
function loadConfig() {
|
|
33
|
+
async function loadConfig() {
|
|
34
34
|
const configPath = path.join(process.cwd(), 'ilana.config.js');
|
|
35
35
|
if (fs.existsSync(configPath)) {
|
|
36
36
|
delete require.cache[configPath];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
try {
|
|
38
|
+
const config = require(configPath);
|
|
39
|
+
// Config file already initializes database
|
|
40
|
+
return config;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error.code === 'ERR_REQUIRE_ESM') {
|
|
43
|
+
// Handle ES modules
|
|
44
|
+
const configModule = await import(configPath);
|
|
45
|
+
const config = configModule.default || configModule;
|
|
46
|
+
return config;
|
|
47
|
+
} else {
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
52
|
// No config file found - don't initialize with hardcoded default
|
|
42
53
|
console.error('No ilana.config.js found. Run "npx ilana setup" first.');
|
|
@@ -44,8 +55,8 @@ function loadConfig() {
|
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
// Initialize database
|
|
47
|
-
function initializeDatabase() {
|
|
48
|
-
loadConfig(); // Config handles initialization
|
|
58
|
+
async function initializeDatabase() {
|
|
59
|
+
await loadConfig(); // Config handles initialization
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
// Helper functions
|
|
@@ -449,7 +460,7 @@ DB_TIMEZONE=UTC
|
|
|
449
460
|
}
|
|
450
461
|
}
|
|
451
462
|
|
|
452
|
-
initializeDatabase();
|
|
463
|
+
await initializeDatabase();
|
|
453
464
|
const runner = new MigrationRunner();
|
|
454
465
|
runner.generateMigration(name, tableName, isCreate);
|
|
455
466
|
},
|
|
@@ -524,14 +535,14 @@ DB_TIMEZONE=UTC
|
|
|
524
535
|
}
|
|
525
536
|
|
|
526
537
|
if (options.migration || options.all) {
|
|
527
|
-
initializeDatabase();
|
|
538
|
+
await initializeDatabase();
|
|
528
539
|
}
|
|
529
540
|
|
|
530
541
|
generateModel(name, options);
|
|
531
542
|
},
|
|
532
543
|
|
|
533
544
|
async migrate(...args) {
|
|
534
|
-
initializeDatabase();
|
|
545
|
+
await initializeDatabase();
|
|
535
546
|
const runner = new MigrationRunner();
|
|
536
547
|
|
|
537
548
|
let connection;
|
|
@@ -565,7 +576,7 @@ DB_TIMEZONE=UTC
|
|
|
565
576
|
},
|
|
566
577
|
|
|
567
578
|
async 'migrate:fresh'(...args) {
|
|
568
|
-
initializeDatabase();
|
|
579
|
+
await initializeDatabase();
|
|
569
580
|
const runner = new MigrationRunner();
|
|
570
581
|
|
|
571
582
|
let connection;
|
|
@@ -591,21 +602,21 @@ DB_TIMEZONE=UTC
|
|
|
591
602
|
},
|
|
592
603
|
|
|
593
604
|
async 'migrate:list'(connection) {
|
|
594
|
-
initializeDatabase();
|
|
605
|
+
await initializeDatabase();
|
|
595
606
|
const runner = new MigrationRunner();
|
|
596
607
|
await runner.list(connection);
|
|
597
608
|
process.exit(0);
|
|
598
609
|
},
|
|
599
610
|
|
|
600
611
|
async 'migrate:unlock'(connection) {
|
|
601
|
-
initializeDatabase();
|
|
612
|
+
await initializeDatabase();
|
|
602
613
|
const runner = new MigrationRunner();
|
|
603
614
|
await runner.unlock(connection);
|
|
604
615
|
process.exit(0);
|
|
605
616
|
},
|
|
606
617
|
|
|
607
618
|
async 'migrate:rollback'(...args) {
|
|
608
|
-
initializeDatabase();
|
|
619
|
+
await initializeDatabase();
|
|
609
620
|
const runner = new MigrationRunner();
|
|
610
621
|
|
|
611
622
|
let steps = 1;
|
|
@@ -641,28 +652,28 @@ DB_TIMEZONE=UTC
|
|
|
641
652
|
},
|
|
642
653
|
|
|
643
654
|
async 'migrate:reset'(connection) {
|
|
644
|
-
initializeDatabase();
|
|
655
|
+
await initializeDatabase();
|
|
645
656
|
const runner = new MigrationRunner();
|
|
646
657
|
await runner.reset(connection);
|
|
647
658
|
process.exit(0);
|
|
648
659
|
},
|
|
649
660
|
|
|
650
661
|
async 'migrate:refresh'(connection) {
|
|
651
|
-
initializeDatabase();
|
|
662
|
+
await initializeDatabase();
|
|
652
663
|
const runner = new MigrationRunner();
|
|
653
664
|
await runner.refresh(connection);
|
|
654
665
|
process.exit(0);
|
|
655
666
|
},
|
|
656
667
|
|
|
657
668
|
async 'migrate:status'(connection) {
|
|
658
|
-
initializeDatabase();
|
|
669
|
+
await initializeDatabase();
|
|
659
670
|
const runner = new MigrationRunner();
|
|
660
671
|
await runner.status(connection);
|
|
661
672
|
process.exit(0);
|
|
662
673
|
},
|
|
663
674
|
|
|
664
675
|
async seed(...args) {
|
|
665
|
-
initializeDatabase();
|
|
676
|
+
await initializeDatabase();
|
|
666
677
|
|
|
667
678
|
let seederName;
|
|
668
679
|
let connection;
|
|
@@ -710,7 +721,19 @@ DB_TIMEZONE=UTC
|
|
|
710
721
|
console.log(`Seeding: ${file}`);
|
|
711
722
|
const filepath = path.join(seedsPath, file);
|
|
712
723
|
delete require.cache[filepath];
|
|
713
|
-
|
|
724
|
+
|
|
725
|
+
let seederModule;
|
|
726
|
+
try {
|
|
727
|
+
seederModule = require(filepath);
|
|
728
|
+
} catch (error) {
|
|
729
|
+
if (error.code === 'ERR_REQUIRE_ESM') {
|
|
730
|
+
// Handle ES modules
|
|
731
|
+
seederModule = await import(filepath);
|
|
732
|
+
} else {
|
|
733
|
+
throw error;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
714
737
|
const SeederClass = seederModule.default || seederModule;
|
|
715
738
|
const seeder = new SeederClass();
|
|
716
739
|
|
|
@@ -734,7 +757,7 @@ DB_TIMEZONE=UTC
|
|
|
734
757
|
},
|
|
735
758
|
|
|
736
759
|
async 'db:wipe'(connection) {
|
|
737
|
-
initializeDatabase();
|
|
760
|
+
await initializeDatabase();
|
|
738
761
|
const runner = new MigrationRunner();
|
|
739
762
|
await runner.wipe(connection);
|
|
740
763
|
process.exit(0);
|
package/orm/MigrationRunner.js
CHANGED
|
@@ -6,11 +6,24 @@ const SchemaBuilder = require('../database/schema-builder');
|
|
|
6
6
|
let config = {};
|
|
7
7
|
|
|
8
8
|
// Auto-load configuration on first import
|
|
9
|
-
(function autoLoadConfig() {
|
|
9
|
+
(async function autoLoadConfig() {
|
|
10
10
|
const configPath = path.join(process.cwd(), 'ilana.config.js');
|
|
11
11
|
if (fs.existsSync(configPath)) {
|
|
12
12
|
delete require.cache[configPath];
|
|
13
|
-
|
|
13
|
+
try {
|
|
14
|
+
config = require(configPath) || {}; // Config file handles Database.configure()
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (error.code === 'ERR_REQUIRE_ESM') {
|
|
17
|
+
// Handle ES modules
|
|
18
|
+
const configModule = await import(configPath);
|
|
19
|
+
config = configModule.default || configModule;
|
|
20
|
+
if (typeof config.configure === 'function') {
|
|
21
|
+
config.configure(config);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
14
27
|
}
|
|
15
28
|
})();
|
|
16
29
|
|
|
@@ -293,7 +306,18 @@ class MigrationRunner {
|
|
|
293
306
|
async loadMigration(filename) {
|
|
294
307
|
const filepath = path.resolve(this.migrationsPath, filename);
|
|
295
308
|
delete require.cache[filepath];
|
|
296
|
-
|
|
309
|
+
|
|
310
|
+
let migrationModule;
|
|
311
|
+
try {
|
|
312
|
+
migrationModule = require(filepath);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (error.code === 'ERR_REQUIRE_ESM') {
|
|
315
|
+
// Handle ES modules
|
|
316
|
+
migrationModule = await import(filepath);
|
|
317
|
+
} else {
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
297
321
|
|
|
298
322
|
const MigrationClass = migrationModule.default || migrationModule;
|
|
299
323
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ilana-orm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A fully-featured, Eloquent-style ORM for Node.js with TypeScript support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"type": "git",
|
|
33
33
|
"url": "https://github.com/raphyabak/ilana-orm.git"
|
|
34
34
|
},
|
|
35
|
-
"homepage": "https://
|
|
35
|
+
"homepage": "https://raphwebb.mintlify.com",
|
|
36
36
|
"bugs": {
|
|
37
37
|
"url": "https://github.com/raphyabak/ilana-orm/issues"
|
|
38
38
|
},
|
|
@@ -68,4 +68,4 @@
|
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=16.0.0"
|
|
70
70
|
}
|
|
71
|
-
}
|
|
71
|
+
}
|