Bansari Akhani commited on
Commit
39bf8fb
·
1 Parent(s): 154c653

add unique constarint to workorder number

Browse files
src/db/migrations/20241119061806-add-unique-constraint-to-workorder_number.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('sequelize-cli').Migration} */
4
+ module.exports = {
5
+ async up (queryInterface, Sequelize) {
6
+ await queryInterface.addConstraint('pw_workorders', {
7
+ fields: ['number'],
8
+ type: 'unique',
9
+ name: 'unique_number_constraint'
10
+ });
11
+ },
12
+
13
+ async down (queryInterface, Sequelize) {
14
+ await queryInterface.removeConstraint('pw_workorders', 'unique_number_constraint');
15
+ }
16
+ };
src/models/pwWorkOrders.ts CHANGED
@@ -30,10 +30,12 @@ PwWorkOrders.init(
30
  pw_id: {
31
  type: DataTypes.BIGINT,
32
  allowNull: false,
 
33
  },
34
  number: {
35
  type: DataTypes.BIGINT,
36
  allowNull: false,
 
37
  },
38
  location: {
39
  type: DataTypes.STRING,
 
30
  pw_id: {
31
  type: DataTypes.BIGINT,
32
  allowNull: false,
33
+ unique: true,
34
  },
35
  number: {
36
  type: DataTypes.BIGINT,
37
  allowNull: false,
38
+ unique: true,
39
  },
40
  location: {
41
  type: DataTypes.STRING,