Files
vitfit-r2/V2/app/modules/timers/migrations/007-timers-v2.js
T
2026-06-13 08:03:45 -04:00

39 lines
1.7 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
const tableDesc = await queryInterface.describeTable('Timers').catch(() => null);
if (!tableDesc) {
await queryInterface.createTable('Timers', {
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
organizationId: { type: Sequelize.INTEGER, allowNull: false },
name: { type: Sequelize.STRING, allowNull: false },
totalTime: { type: Sequelize.INTEGER, allowNull: false },
setTime: { type: Sequelize.INTEGER, allowNull: false },
restTime: { type: Sequelize.INTEGER, defaultValue: 0 },
moveTime: { type: Sequelize.INTEGER, defaultValue: 0 },
setCount: { type: Sequelize.INTEGER, allowNull: false },
exerciseCount: { type: Sequelize.INTEGER, allowNull: false },
lapCount: { type: Sequelize.INTEGER, defaultValue: 1 },
createdByUserId: { type: Sequelize.INTEGER },
createdAt: { type: Sequelize.DATE, allowNull: false },
updatedAt: { type: Sequelize.DATE, allowNull: false },
});
return;
}
const addIfMissing = async (col, def) => {
if (!tableDesc[col]) await queryInterface.addColumn('Timers', col, def);
};
await addIfMissing('organizationId', { type: Sequelize.INTEGER });
await addIfMissing('name', { type: Sequelize.STRING, allowNull: false, defaultValue: 'Timer' });
await addIfMissing('createdByUserId', { type: Sequelize.INTEGER });
},
async down(queryInterface) {
await queryInterface.dropTable('Timers').catch(() => {});
},
};