fix(sql-tools)!: separate runtime and source migration folders (#687)

* fix(sql-tools)!: separate runtime and source migration folders

* chore: formatting
This commit is contained in:
bo0tzz
2026-08-11 14:40:33 +02:00
committed by GitHub
parent 8082995101
commit 942478ffb8
2 changed files with 13 additions and 13 deletions
+7 -7
View File
@@ -25,7 +25,12 @@ const program = new Command('sql-tools');
program
.requiredOption('-u, --url <url>', 'Database connection url')
.option('-f, --folder <migrationsFolder>', 'Path to the migration files', 'dist/schema/migrations');
.option(
'-f, --folder <migrationsFolder>',
'Path to the runnable (compiled) migration files',
'dist/schema/migrations',
)
.option('--source-folder <migrationsSourceFolder>', 'Path to the migration source files', 'src/schema/migrations');
program
.command('query')
@@ -48,12 +53,7 @@ migrations
migrations
.command('revert')
.description('Revert the most recent migration')
.requiredOption(
'-f, --folder <migrationsFolder>',
'Path to the folder the migration files are in',
'src/schema/migrations',
)
.action(withMigrator((migrator, { folder }) => migrator.revert(join(process.cwd(), folder))));
.action(withMigrator((migrator, { sourceFolder }) => migrator.revert(join(process.cwd(), sourceFolder))));
migrations
.command('create')
+6 -6
View File
@@ -129,14 +129,14 @@ export class Migrator {
return reverted.migrationName;
}
async revert(migrationsDistFolder: string) {
async revert(sourceFolder: string) {
const migrationName = await this.#revertLastMigration();
if (!migrationName) {
console.log('No migrations to revert');
return;
}
this.#markMigrationAsReverted(migrationName, migrationsDistFolder);
this.#markMigrationAsReverted(migrationName, sourceFolder);
}
async generate({ dist, targetPath, withComments }: { dist: string; targetPath: string; withComments: boolean }) {
@@ -217,9 +217,9 @@ ${downSql}
`;
}
#markMigrationAsReverted(migrationName: string, migrationsDistFolder: string) {
const sourcePath = join(this.#migrationsFolder, `${migrationName}.ts`);
const revertedFolder = join(this.#migrationsFolder, 'reverted');
#markMigrationAsReverted(migrationName: string, sourceFolder: string) {
const sourcePath = join(sourceFolder, `${migrationName}.ts`);
const revertedFolder = join(sourceFolder, 'reverted');
const revertedPath = join(revertedFolder, `${migrationName}.ts`);
if (existsSync(revertedPath)) {
@@ -232,7 +232,7 @@ ${downSql}
console.warn(`Source migration file not found for ${migrationName}`);
}
const distBase = join(migrationsDistFolder, migrationName);
const distBase = join(this.#migrationsFolder, migrationName);
for (const extension of ['.js', '.js.map', '.d.ts']) {
const filePath = `${distBase}${extension}`;
if (existsSync(filePath)) {