@noego/proper 0.0.4 → 0.0.6
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/bin/cli.js +55 -17
- package/bin/cli.js.map +1 -1
- package/bin/cli.mjs +55 -17
- package/bin/cli.mjs.map +1 -1
- package/bin/index.d.mts +11 -1
- package/bin/index.d.ts +11 -1
- package/bin/index.js +54 -17
- package/bin/index.js.map +1 -1
- package/bin/index.mjs +60 -17
- package/bin/index.mjs.map +1 -1
- package/package.json +2 -1
package/bin/cli.mjs
CHANGED
|
@@ -420,26 +420,50 @@ var init_MigrationDirectoryReader = __esm({
|
|
|
420
420
|
"framework/MigrationDirectoryReader.ts"() {
|
|
421
421
|
init_SqlMigrationBuilder();
|
|
422
422
|
MigrationDirectoryReader = class {
|
|
423
|
-
constructor(directory, read_strategy, sqlrunner) {
|
|
423
|
+
constructor(directory, read_strategy, sqlrunner, dialect = "sql") {
|
|
424
424
|
this.directory = directory;
|
|
425
425
|
this.read_strategy = read_strategy;
|
|
426
426
|
this.sqlrunner = sqlrunner;
|
|
427
|
+
this.dialect = dialect;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Resolves the appropriate file for a migration based on dialect.
|
|
431
|
+
* Priority: dialect-specific file > generic file
|
|
432
|
+
*/
|
|
433
|
+
resolveFile(baseName, direction) {
|
|
434
|
+
const dialectExt = this.dialect === "sql" ? "mysql" : "sqlite";
|
|
435
|
+
const dialectFile = path.join(this.directory, `${baseName}.${dialectExt}.${direction}.sql`);
|
|
436
|
+
if (fs.existsSync(dialectFile)) return dialectFile;
|
|
437
|
+
const genericFile = path.join(this.directory, `${baseName}.${direction}.sql`);
|
|
438
|
+
if (fs.existsSync(genericFile)) return genericFile;
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Checks if a file path is dialect-specific (contains .mysql. or .sqlite. in the name)
|
|
443
|
+
*/
|
|
444
|
+
isDialectSpecific(filePath) {
|
|
445
|
+
return /\.(mysql|sqlite)\.(up|down)\.sql$/i.test(filePath);
|
|
427
446
|
}
|
|
428
447
|
loadMigrations(table, connection) {
|
|
429
448
|
fs.existsSync(this.directory) || fs.mkdirSync(this.directory);
|
|
430
449
|
const dir_content = fs.readdirSync(this.directory, { withFileTypes: true }).filter((file) => file.isFile()).map((file) => file.name);
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
file
|
|
437
|
-
};
|
|
438
|
-
}).sort();
|
|
450
|
+
const uniqueKeys = /* @__PURE__ */ new Set();
|
|
451
|
+
dir_content.forEach((file) => {
|
|
452
|
+
const key = file.replace(/(?:\.(mysql|sqlite))?\.(up|down)\.(sql|js)/i, "").toLowerCase();
|
|
453
|
+
uniqueKeys.add(key);
|
|
454
|
+
});
|
|
439
455
|
const migration_sorter = {};
|
|
440
|
-
|
|
441
|
-
const builder =
|
|
442
|
-
this.
|
|
456
|
+
uniqueKeys.forEach((migration_key) => {
|
|
457
|
+
const builder = new SqlMigrationBuilder(migration_key);
|
|
458
|
+
const upFile = this.resolveFile(migration_key, "up");
|
|
459
|
+
const downFile = this.resolveFile(migration_key, "down");
|
|
460
|
+
if (upFile) {
|
|
461
|
+
this.loadMigration(builder, upFile);
|
|
462
|
+
}
|
|
463
|
+
if (downFile) {
|
|
464
|
+
this.loadMigration(builder, downFile);
|
|
465
|
+
}
|
|
466
|
+
migration_sorter[migration_key] = builder;
|
|
443
467
|
});
|
|
444
468
|
const keys = Object.keys(migration_sorter);
|
|
445
469
|
keys.sort();
|
|
@@ -466,12 +490,16 @@ var init_MigrationDirectoryReader = __esm({
|
|
|
466
490
|
}
|
|
467
491
|
sql_up(file) {
|
|
468
492
|
let content = fs.readFileSync(file).toString();
|
|
469
|
-
|
|
493
|
+
if (!this.isDialectSpecific(file)) {
|
|
494
|
+
content = this.read_strategy(content);
|
|
495
|
+
}
|
|
470
496
|
return content.trim();
|
|
471
497
|
}
|
|
472
498
|
sql_down(file) {
|
|
473
499
|
let content = fs.readFileSync(file).toString();
|
|
474
|
-
|
|
500
|
+
if (!this.isDialectSpecific(file)) {
|
|
501
|
+
content = this.read_strategy(content);
|
|
502
|
+
}
|
|
475
503
|
return content.trim();
|
|
476
504
|
}
|
|
477
505
|
};
|
|
@@ -878,7 +906,7 @@ var init_MigrationRunner = __esm({
|
|
|
878
906
|
}
|
|
879
907
|
const setup = new MigrationSetup(sqlrunner, config);
|
|
880
908
|
const read_strategy = this.getReadStategy(config);
|
|
881
|
-
const migration_files = new MigrationDirectoryReader(config.migration_folder, read_strategy, sqlrunner);
|
|
909
|
+
const migration_files = new MigrationDirectoryReader(config.migration_folder, read_strategy, sqlrunner, config.database);
|
|
882
910
|
yield setup.setup();
|
|
883
911
|
return new MySQLMigrationRunner(config, migration_files, setup, sqlrunner, driverConnection);
|
|
884
912
|
});
|
|
@@ -899,7 +927,7 @@ var init_MigrationRunner = __esm({
|
|
|
899
927
|
}
|
|
900
928
|
const setup = new MigrationSetup(sqlrunner, config);
|
|
901
929
|
const read_strategy = this.getReadStategy(config);
|
|
902
|
-
const migration_files = new MigrationDirectoryReader(config.migration_folder, read_strategy, sqlrunner);
|
|
930
|
+
const migration_files = new MigrationDirectoryReader(config.migration_folder, read_strategy, sqlrunner, config.database);
|
|
903
931
|
return new MySQLMigrationRunner(config, migration_files, setup, sqlrunner, conn);
|
|
904
932
|
});
|
|
905
933
|
}
|
|
@@ -1285,10 +1313,19 @@ function runSqlSeed(runner, resolved, direction) {
|
|
|
1285
1313
|
yield runner.query(sql);
|
|
1286
1314
|
});
|
|
1287
1315
|
}
|
|
1316
|
+
function loadSeedModule(modulePath) {
|
|
1317
|
+
return __async(this, null, function* () {
|
|
1318
|
+
const resolved = path2.resolve(modulePath);
|
|
1319
|
+
if (resolved.endsWith(".ts")) {
|
|
1320
|
+
return __require(resolved);
|
|
1321
|
+
}
|
|
1322
|
+
return import(resolved);
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1288
1325
|
function runModuleSeed(runner, resolved, migrationConfig, options, direction) {
|
|
1289
1326
|
return __async(this, null, function* () {
|
|
1290
1327
|
const { log } = options;
|
|
1291
|
-
const module = yield
|
|
1328
|
+
const module = yield loadSeedModule(resolved.upPath);
|
|
1292
1329
|
const handler = module[direction];
|
|
1293
1330
|
if (typeof handler !== "function") {
|
|
1294
1331
|
throw new Error(`Seed module "${resolved.name}" does not export ${direction}()`);
|
|
@@ -1372,6 +1409,7 @@ var init_SeedRunner = __esm({
|
|
|
1372
1409
|
|
|
1373
1410
|
// cli.ts
|
|
1374
1411
|
import "source-map-support/register";
|
|
1412
|
+
import "tsx/cjs";
|
|
1375
1413
|
var require_cli = __commonJS({
|
|
1376
1414
|
"cli.ts"(exports) {
|
|
1377
1415
|
init_MigrationCLi();
|