29 lines
964 B
JavaScript
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(() => {});
|
|
}
|
|
},
|
|
};
|