Files
starr-philproperties/apps/api/database/migrations/20270101000069-create-certificates.js
T

35 lines
1.8 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('certificates', {
certificate_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: Sequelize.UUID, allowNull: false, unique: true, defaultValue: Sequelize.literal('gen_random_uuid()') },
cert_no: { type: Sequelize.STRING(25), allowNull: false, unique: true },
ref_no: { type: Sequelize.STRING(50), allowNull: false },
user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
course_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'courses', key: 'course_id' }, onDelete: 'CASCADE' },
instructors: { type: Sequelize.TEXT, allowNull: true },
score: { type: Sequelize.BIGINT, allowNull: true },
length_str: { type: Sequelize.STRING(50), allowNull: true },
issued_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
updated_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
});
await queryInterface.addConstraint('certificates', {
fields: ['user_id', 'course_id'],
type: 'unique',
name: 'certificates_user_id_course_id_key',
});
await queryInterface.addIndex('certificates', ['course_id'], { name: 'idx_certificates_course_id' });
await queryInterface.addIndex('certificates', ['user_id'], { name: 'idx_certificates_user_id' });
await queryInterface.addIndex('certificates', ['uuid'], { name: 'idx_certificates_uuid' });
},
async down(queryInterface) {
await queryInterface.dropTable('certificates');
},
};