42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = {
|
|
async up(queryInterface, Sequelize) {
|
|
const tableDesc = await queryInterface.describeTable('Workouts').catch(() => null);
|
|
|
|
if (!tableDesc) {
|
|
await queryInterface.createTable('Workouts', {
|
|
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
|
|
organizationId: { type: Sequelize.INTEGER, allowNull: false },
|
|
name: { type: Sequelize.STRING },
|
|
workoutDate: { type: Sequelize.DATE },
|
|
video1: { type: Sequelize.INTEGER },
|
|
video2: { type: Sequelize.INTEGER },
|
|
video3: { type: Sequelize.INTEGER },
|
|
video4: { type: Sequelize.INTEGER },
|
|
number1: { type: Sequelize.INTEGER },
|
|
number2: { type: Sequelize.INTEGER },
|
|
number3: { type: Sequelize.INTEGER },
|
|
number4: { type: Sequelize.INTEGER },
|
|
createdByUserId: { type: Sequelize.INTEGER },
|
|
createdAt: { type: Sequelize.DATE, allowNull: false },
|
|
updatedAt: { type: Sequelize.DATE, allowNull: false },
|
|
});
|
|
|
|
await queryInterface.addIndex('Workouts', ['organizationId', 'workoutDate']);
|
|
return;
|
|
}
|
|
|
|
const addIfMissing = async (col, def) => {
|
|
if (!tableDesc[col]) await queryInterface.addColumn('Workouts', col, def);
|
|
};
|
|
|
|
await addIfMissing('organizationId', { type: Sequelize.INTEGER });
|
|
await addIfMissing('createdByUserId', { type: Sequelize.INTEGER });
|
|
},
|
|
|
|
async down(queryInterface) {
|
|
await queryInterface.dropTable('Workouts').catch(() => {});
|
|
},
|
|
};
|