61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
const { Sequelize } = require("sequelize");
|
|
|
|
module.exports = {
|
|
async up(queryInterface) {
|
|
await queryInterface.createTable("student", {
|
|
ID_SISWA: {
|
|
type: Sequelize.UUID,
|
|
primaryKey: true,
|
|
defaultValue: Sequelize.UUIDV4,
|
|
allowNull: false,
|
|
},
|
|
ID_CLASS: {
|
|
type: Sequelize.UUID,
|
|
allowNull: true,
|
|
},
|
|
ID: {
|
|
type: Sequelize.UUID,
|
|
allowNull: false,
|
|
},
|
|
NISN: {
|
|
type: Sequelize.BIGINT(11),
|
|
allowNull: false,
|
|
},
|
|
});
|
|
|
|
await queryInterface.addConstraint("student", {
|
|
fields: ["NISN"],
|
|
type: "unique",
|
|
name: "student_unique_nisn",
|
|
});
|
|
|
|
await queryInterface.addConstraint("student", {
|
|
fields: ["ID_CLASS"],
|
|
type: "foreign key",
|
|
name: "FK_MENAMPUNG",
|
|
references: {
|
|
table: "class",
|
|
field: "ID_CLASS",
|
|
},
|
|
onUpdate: "CASCADE",
|
|
onDelete: "SET NULL",
|
|
});
|
|
|
|
await queryInterface.addConstraint("student", {
|
|
fields: ["ID"],
|
|
type: "foreign key",
|
|
name: "FK_MENJADI",
|
|
references: {
|
|
table: "users",
|
|
field: "ID",
|
|
},
|
|
onUpdate: "CASCADE",
|
|
onDelete: "CASCADE",
|
|
});
|
|
},
|
|
|
|
async down(queryInterface) {
|
|
await queryInterface.dropTable("student");
|
|
},
|
|
};
|