lms-sync 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- const db = require('../models')
1
+ const {db, schema} = require('../models')
2
2
  const logger = require('../utils/logger')
3
3
  const api = require('../apiConnections/apiConnects')
4
4
  const moment = require('moment')
@@ -39,9 +39,10 @@ const server = {
39
39
  let errorCounter = 0
40
40
  let uniqueErrors = new Set()
41
41
 
42
- // let maxIds = await Campuses.max('_id'); // Fetch maximum _id directly from the campuses model
42
+ const db_schema = schema
43
+ // let maxIds = await Campuses.max('_id'); = await Campuses.max('_id'); // Fetch maximum _id directly from the campuses model
43
44
  // let maxId = maxIds|| 0;
44
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Campuses__id_seq" RESTART WITH ${maxId + 1}`);
45
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Campuses__id_seq" RESTART WITH ${maxId + 1}`);
45
46
 
46
47
  for (let i = 0; i < campusApi.length; i++){
47
48
  try {
@@ -123,9 +124,10 @@ const server = {
123
124
  let errorCounter = 0
124
125
  let uniqueErrors = new Set()
125
126
 
126
- // let maxIds = await Colleges.max('_id'); // Fetch maximum _id directly from the Colleges model
127
+ const db_schema = schema
128
+ // let maxIds = await Campuses.max('_id'); = await Colleges.max('_id'); // Fetch maximum _id directly from the Colleges model
127
129
  // let maxId = maxIds|| 0;
128
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Colleges__id_seq" RESTART WITH ${maxId + 1}`);
130
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Colleges__id_seq" RESTART WITH ${maxId + 1}`);
129
131
 
130
132
  for (let i = 0; i < collegeApi.length; i++){
131
133
  try {
@@ -215,9 +217,10 @@ const server = {
215
217
  let errorCounter = 0
216
218
  let uniqueErrors = new Set()
217
219
 
218
- // let maxIds = await AcademicDepartments.max('_id'); // Fetch maximum _id directly from the AcademicDepartments model
220
+ const db_schema = schema
221
+ // let maxIds = await Campuses.max('_id'); = await AcademicDepartments.max('_id'); // Fetch maximum _id directly from the AcademicDepartments model
219
222
  // let maxId = maxIds|| 0;
220
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."AcademicDepartments__id_seq" RESTART WITH ${maxId + 1}`);
223
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."AcademicDepartments__id_seq" RESTART WITH ${maxId + 1}`);
221
224
  for (let i = 0; i < departmentApi.length; i++){
222
225
  try {
223
226
  let _acadDept = departmentApi[i]
@@ -319,9 +322,10 @@ const server = {
319
322
  let errorCounter = 0
320
323
  let uniqueErrors = new Set()
321
324
 
322
- // let maxIds = await Courses.max('_id'); // Fetch maximum _id directly from the Courses model
325
+ const db_schema = schema
326
+ // let maxIds = await Campuses.max('_id'); = await Courses.max('_id'); // Fetch maximum _id directly from the Courses model
323
327
  // let maxId = maxIds|| 0;
324
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Courses__id_seq" RESTART WITH ${maxId + 1}`);
328
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Courses__id_seq" RESTART WITH ${maxId + 1}`);
325
329
 
326
330
  for (let i = 0; i < studentApi.length; i++){
327
331
  try {
@@ -426,9 +430,10 @@ const server = {
426
430
  let uniqueErrors = new Set()
427
431
 
428
432
 
429
- // let maxIds = await Rooms.max('_id'); // Fetch maximum _id directly from the Rooms model
433
+ const db_schema = schema
434
+ // let maxIds = await Campuses.max('_id'); = await Rooms.max('_id'); // Fetch maximum _id directly from the Rooms model
430
435
  // let maxId = maxIds|| 0;
431
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Rooms__id_seq" RESTART WITH ${maxId + 1}`);
436
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Rooms__id_seq" RESTART WITH ${maxId + 1}`);
432
437
 
433
438
 
434
439
  for (let i = 0; i < roomApi.length; i++){
@@ -536,9 +541,10 @@ const server = {
536
541
  let uniqueErrors = new Set()
537
542
 
538
543
 
539
- // let maxIds = await Instructors.max('_id'); // Fetch maximum _id directly from the Instructors model
544
+ const db_schema = schema
545
+ // let maxIds = await Campuses.max('_id'); = await Instructors.max('_id'); // Fetch maximum _id directly from the Instructors model
540
546
  // let maxId = maxIds|| 0;
541
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Instructors__id_seq" RESTART WITH ${maxId + 1}`);
547
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Instructors__id_seq" RESTART WITH ${maxId + 1}`);
542
548
 
543
549
 
544
550
  for (let i = 0; i < instructorApi.length; i++){
@@ -639,9 +645,10 @@ const server = {
639
645
  const { acadYearResult, currentSchoolYear } = acadYearApi;
640
646
 
641
647
 
642
- // let maxIds = await AcademicYears.max('_id'); // Fetch maximum _id directly from the AcademicYears model
648
+ const db_schema = schema
649
+ // let maxIds = await Campuses.max('_id'); = await AcademicYears.max('_id'); // Fetch maximum _id directly from the AcademicYears model
643
650
  // let maxId = maxIds|| 0;
644
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."AcademicYears__id_seq" RESTART WITH ${maxId + 1}`);
651
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."AcademicYears__id_seq" RESTART WITH ${maxId + 1}`);
645
652
 
646
653
 
647
654
  for (let i = 0; i < acadYearResult.length; i++){
@@ -736,9 +743,10 @@ const server = {
736
743
  let uniqueErrors = new Set()
737
744
 
738
745
 
739
- // let maxIds = await Subjects.max('_id'); // Fetch maximum _id directly from the Subjects model
746
+ const db_schema = schema
747
+ // let maxIds = await Campuses.max('_id'); = await Subjects.max('_id'); // Fetch maximum _id directly from the Subjects model
740
748
  // let maxId = maxIds|| 0;
741
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Subjects__id_seq" RESTART WITH ${maxId + 1}`);
749
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Subjects__id_seq" RESTART WITH ${maxId + 1}`);
742
750
 
743
751
 
744
752
  for (let i = 0; i < studentSubject.length; i++){
@@ -848,9 +856,10 @@ const server = {
848
856
  let uniqueErrors = new Set()
849
857
 
850
858
 
851
- // let maxIds = await Schedules.max('_id'); // Fetch maximum _id directly from the Schedules model
859
+ const db_schema = schema
860
+ // let maxIds = await Campuses.max('_id'); = await Schedules.max('_id'); // Fetch maximum _id directly from the Schedules model
852
861
  // let maxId = maxIds|| 0;
853
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Schedules__id_seq" RESTART WITH ${maxId + 1}`);
862
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Schedules__id_seq" RESTART WITH ${maxId + 1}`);
854
863
 
855
864
  for (let i = 0; i < scheduleApi.length; i++){
856
865
  try {
@@ -974,9 +983,10 @@ const server = {
974
983
  const emailDomain = 'default.msc.edu.ph';
975
984
 
976
985
 
977
- // let maxIds = await Students.max('_id'); // Fetch maximum _id directly from the Students model
986
+ const db_schema = schema
987
+ // let maxIds = await Campuses.max('_id'); = await Students.max('_id'); // Fetch maximum _id directly from the Students model
978
988
  // let maxId = maxIds|| 0;
979
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Students__id_seq" RESTART WITH ${maxId + 1}`);
989
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Students__id_seq" RESTART WITH ${maxId + 1}`);
980
990
 
981
991
  const {data} = studentApi
982
992
  for (let i = 0; i < data.length; i++){
@@ -1104,9 +1114,10 @@ const server = {
1104
1114
  let uniqueErrors = new Set()
1105
1115
 
1106
1116
 
1107
- // let maxIds = await Sections.max('_id'); // Fetch maximum _id directly from the Sections model
1117
+ const db_schema = schema
1118
+ // let maxIds = await Campuses.max('_id'); = await Sections.max('_id'); // Fetch maximum _id directly from the Sections model
1108
1119
  // let maxId = maxIds|| 0;
1109
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."Sections__id_seq" RESTART WITH ${maxId + 1}`);
1120
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Sections__id_seq" RESTART WITH ${maxId + 1}`);
1110
1121
 
1111
1122
 
1112
1123
  for (let i = 0; i < student.length; i++) {
@@ -1187,6 +1198,7 @@ const server = {
1187
1198
  // campusId: _campus?._id??null,
1188
1199
  // modifiedById,
1189
1200
  // createdById,
1201
+
1190
1202
  }
1191
1203
  });
1192
1204
 
@@ -1258,9 +1270,10 @@ const server = {
1258
1270
  let uniqueErrors = new Set()
1259
1271
 
1260
1272
 
1261
- // let maxIds = await EnrolledStudents.max('_id'); // Fetch maximum _id directly from the EnrolledStudents model
1273
+ const db_schema = schema
1274
+ // let maxIds = await Campuses.max('_id'); = await EnrolledStudents.max('_id'); // Fetch maximum _id directly from the EnrolledStudents model
1262
1275
  // let maxId = maxIds|| 0;
1263
- // await db.sequelize.query(`ALTER SEQUENCE public_migrations."EnrolledStudents__id_seq" RESTART WITH ${maxId + 1}`);
1276
+ // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."EnrolledStudents__id_seq" RESTART WITH ${maxId + 1}`);
1264
1277
 
1265
1278
 
1266
1279
  for (let i = 0; i < studentApi.length; i++){
package/models/index.js CHANGED
@@ -45,4 +45,4 @@ Object.keys(db).forEach(modelName => {
45
45
  db.sequelize = sequelize;
46
46
  db.Sequelize = Sequelize;
47
47
 
48
- module.exports = db;
48
+ module.exports = {db, schema};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lms-sync",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Migration App for MSC LMS",
5
5
  "main": "index.js",
6
6
  "scripts": {