backend_adaptive_learning/database/migrations/20241014082720-create-monitoring.cjs

75 lines
1.7 KiB
JavaScript
Raw Normal View History

const { Sequelize } = require("sequelize");
module.exports = {
async up(queryInterface) {
await queryInterface.createTable("monitoring", {
ID_MONITORING: {
type: Sequelize.UUID,
primaryKey: true,
defaultValue: Sequelize.UUIDV4,
allowNull: false,
},
ID_STUDENT_LEARNING: {
type: Sequelize.UUID,
allowNull: false,
},
ID_CLASS: {
type: Sequelize.UUID,
allowNull: true,
},
ID_GURU: {
type: Sequelize.UUID,
allowNull: true,
},
FEEDBACK_GURU: {
type: Sequelize.STRING(200),
allowNull: true,
},
TIME_MONITORING: {
type: Sequelize.DATE,
allowNull: true,
defaultValue: Sequelize.NOW,
},
});
await queryInterface.addConstraint("monitoring", {
fields: ["ID_STUDENT_LEARNING"],
type: "foreign key",
name: "FK_MENGACU",
references: {
table: "student_learning",
field: "ID_STUDENT_LEARNING",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
});
await queryInterface.addConstraint("monitoring", {
fields: ["ID_CLASS"],
type: "foreign key",
name: "FK_MENDAPATKAN",
references: {
table: "class",
field: "ID_CLASS",
},
onUpdate: "CASCADE",
onDelete: "SET NULL",
});
await queryInterface.addConstraint("monitoring", {
fields: ["ID_GURU"],
type: "foreign key",
name: "FK_DILAKUKAN",
references: {
table: "teacher",
field: "ID_GURU",
},
onUpdate: "CASCADE",
onDelete: "SET NULL",
});
},
async down(queryInterface) {
await queryInterface.dropTable("monitoring");
},
};