feat: Add name column to Step model

This commit is contained in:
Faruk AYDIN
2025-01-06 16:42:00 +03:00
parent f9731824eb
commit bc87e18d3f
16 changed files with 58 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
import toLower from 'lodash/toLower.js';
import startCase from 'lodash/startCase.js';
import upperFirst from 'lodash/upperFirst.js';
export async function up(knex) {
await knex.schema.table('steps', function (table) {
table.string('name');
});
const rows = await knex('steps').select('id', 'key');
const updates = rows.map((row) => {
if (!row.key) return;
const humanizedKey = upperFirst(toLower(startCase(row.key)));
return knex('steps').where({ id: row.id }).update({ name: humanizedKey });
});
return await Promise.all(updates);
}
export async function down(knex) {
return knex.schema.table('steps', function (table) {
table.dropColumn('name');
});
}