feat: Convert migration file names if there is a table

This commit is contained in:
Faruk AYDIN
2024-01-13 02:58:28 +01:00
parent 9e151051a8
commit 01ef97949b

View File

@@ -9,13 +9,18 @@ export const renameMigrationsAsJsFiles = async () => {
} }
try { try {
await knex.raw( const tableExists = await knex.schema.hasTable('knex_migrations');
`UPDATE knex_migrations SET name = REPLACE(name, '.ts', '.js') WHERE name LIKE '%.ts';`
);
if (tableExists) {
await knex('knex_migrations')
.where('name', 'like', '%.ts')
.update({
name: knex.raw("REPLACE(name, '.ts', '.js')"),
});
logger.info( logger.info(
`Migration file names with typescript renamed as JS file names!` `Migration file names with typescript renamed as JS file names!`
); );
}
} catch (err) { } catch (err) {
logger.error(err.message); logger.error(err.message);
} }