ad7fc4384a
Introduces the skydiver_profile table as an optional 1-to-1 extension of the user table, holding skydive-specific fields (licence, poids, bg_image). Wired up with Sequelize associations and a service with upsert support. Migration, model, relationships, and service layer all included.
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = {
|
|
async up(queryInterface, Sequelize) {
|
|
const transaction = await queryInterface.sequelize.transaction();
|
|
try {
|
|
await queryInterface.createTable('skydiver_profile', {
|
|
userId: {
|
|
type: Sequelize.STRING(36),
|
|
allowNull: false,
|
|
primaryKey: true,
|
|
references: {
|
|
model: 'user',
|
|
key: 'id'
|
|
},
|
|
onDelete: 'CASCADE'
|
|
},
|
|
licence: {
|
|
type: Sequelize.INTEGER,
|
|
allowNull: true
|
|
},
|
|
poids: {
|
|
type: Sequelize.FLOAT,
|
|
allowNull: true
|
|
},
|
|
bg_image: {
|
|
type: Sequelize.STRING(255),
|
|
allowNull: true
|
|
},
|
|
createdAt: {
|
|
type: Sequelize.DATE,
|
|
allowNull: false,
|
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
|
},
|
|
updatedAt: {
|
|
type: Sequelize.DATE,
|
|
allowNull: false,
|
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
|
|
}
|
|
}, { transaction });
|
|
|
|
await transaction.commit();
|
|
} catch (err) {
|
|
await transaction.rollback();
|
|
throw err;
|
|
}
|
|
},
|
|
|
|
async down(queryInterface) {
|
|
await queryInterface.dropTable('skydiver_profile');
|
|
}
|
|
};
|