r2
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
// Create Users table if it doesn't exist (new installs)
|
||||
const tableDesc = await queryInterface.describeTable('Users').catch(() => null);
|
||||
|
||||
if (!tableDesc) {
|
||||
await queryInterface.createTable('Users', {
|
||||
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
organizationId: { type: Sequelize.INTEGER },
|
||||
username: { type: Sequelize.STRING, allowNull: false, unique: true },
|
||||
email: { type: Sequelize.STRING, unique: true },
|
||||
password: { type: Sequelize.STRING, allowNull: false },
|
||||
role: { type: Sequelize.ENUM('SystemAdmin', 'Owner', 'Coach', 'Client'), allowNull: false, defaultValue: 'Coach' },
|
||||
firstName: { type: Sequelize.STRING },
|
||||
lastName: { type: Sequelize.STRING },
|
||||
isActive: { type: Sequelize.BOOLEAN, defaultValue: true },
|
||||
lastLoginAt: { type: Sequelize.DATE },
|
||||
passwordChangedAt: { type: Sequelize.DATE },
|
||||
createdAt: { type: Sequelize.DATE, allowNull: false },
|
||||
updatedAt: { type: Sequelize.DATE, allowNull: false },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// V1 upgrade path: add missing columns
|
||||
const addIfMissing = async (col, def) => {
|
||||
if (!tableDesc[col]) {
|
||||
await queryInterface.addColumn('Users', col, def);
|
||||
}
|
||||
};
|
||||
|
||||
await addIfMissing('organizationId', { type: Sequelize.INTEGER });
|
||||
await addIfMissing('email', { type: Sequelize.STRING });
|
||||
await addIfMissing('firstName', { type: Sequelize.STRING });
|
||||
await addIfMissing('lastName', { type: Sequelize.STRING });
|
||||
await addIfMissing('isActive', { type: Sequelize.BOOLEAN, defaultValue: true });
|
||||
await addIfMissing('lastLoginAt', { type: Sequelize.DATE });
|
||||
await addIfMissing('passwordChangedAt', { type: Sequelize.DATE });
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
// No-op for V1 upgrade path; would need to be more specific for rollback
|
||||
await queryInterface.dropTable('Users').catch(() => {});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
// passwordChangedAt was added in 003 for new installs; this migration ensures
|
||||
// it exists on V1 upgrades where 003 ran the addIfMissing path but may have
|
||||
// been using an older column list.
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
const tableDesc = await queryInterface.describeTable('Users').catch(() => null);
|
||||
if (tableDesc && !tableDesc['passwordChangedAt']) {
|
||||
await queryInterface.addColumn('Users', 'passwordChangedAt', {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.removeColumn('Users', 'passwordChangedAt').catch(() => {});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user