Files
vitfit-r2/V2/app/modules/org/migrations/020-add-missing-updatedAt.js
T
2026-07-02 21:34:54 -04:00

29 lines
964 B
JavaScript

'use strict';
// Workouts, CrossfitWorkouts, and Timers were raw SQL tables in V1 — no updatedAt.
// Sequelize requires updatedAt by default; without this column any write to these
// tables fails. Backfill with createdAt so existing rows have a valid timestamp.
module.exports = {
async up(queryInterface, Sequelize) {
for (const table of ['Workouts', 'CrossfitWorkouts', 'Timers']) {
const cols = await queryInterface.describeTable(table).catch(() => null);
if (!cols || cols['updatedAt']) continue;
await queryInterface.addColumn(table, 'updatedAt', {
type: Sequelize.DATE,
allowNull: true,
});
await queryInterface.sequelize.query(
`UPDATE "${table}" SET "updatedAt" = "createdAt"`
);
}
},
async down(queryInterface) {
for (const table of ['Workouts', 'CrossfitWorkouts', 'Timers']) {
await queryInterface.removeColumn(table, 'updatedAt').catch(() => {});
}
},
};