@@ -185,11 +185,6 @@ if(process.env.PARSE_SERVER_MOUNT_GRAPHQL == 'true'){
185
185
parseGraphQLServer . applyGraphQL ( app ) ; // Mounts the GraphQL API
186
186
}
187
187
188
- // If you are not using ParseCareKit, set PARSE_USING_PARSECAREKIT to 0
189
- if ( process . env . PARSE_USING_PARSECAREKIT == 'true' ) {
190
- createIndexes ( ) ;
191
- }
192
-
193
188
const host = process . env . HOST || '0.0.0.0' ;
194
189
const port = process . env . PORT || 1337 ;
195
190
const httpServer = require ( 'http' ) . createServer ( app ) ;
@@ -202,23 +197,35 @@ httpServer.listen(port, host, function() {
202
197
} ) ;
203
198
204
199
async function createIndexes ( ) {
205
- await Parse . Cloud . run ( 'ensureClassDefaultFieldsForParseCareKit' ) ;
206
200
const adapter = api . config . databaseController . adapter ;
207
201
const indexEntityIdPostfix = '_entityId' ;
208
202
const indexRemoteIdPostfix = '_remoteId' ;
209
203
const indexEffectiveDatePostfix = '_effectiveDate' ;
210
-
204
+ const indexUpdatedDatePostfix = '_updatedDate' ;
205
+ const indexCreatedAtPostfix = '_createdAt' ;
206
+ const indexLogicalClockPostfix = '_logicalClock' ;
207
+
208
+ const parseSchema = {
209
+ fields : {
210
+ createdAt : { type : 'Date' }
211
+ } ,
212
+ } ;
213
+
211
214
const schema = {
212
215
fields : {
213
- uuid : { type : 'String' }
216
+ uuid : { type : 'String' } ,
217
+ createdAt : { type : 'Date' }
214
218
} ,
215
219
} ;
216
220
217
221
const versionedSchema = {
218
222
fields : {
219
223
entityId : { type : 'String' } ,
220
224
remoteID : { type : 'String' } ,
221
- effectiveDate : { type : 'Date' }
225
+ effectiveDate : { type : 'Date' } ,
226
+ updatedDate : { type : 'Date' } ,
227
+ createdAt : { type : 'Date' } ,
228
+ logicalClock : { type : 'Number' }
222
229
} ,
223
230
} ;
224
231
@@ -234,13 +241,45 @@ async function createIndexes(){
234
241
await adapter . ensureIndex ( 'Patient' , versionedSchema , [ 'effectiveDate' ] , 'Patient' + indexEffectiveDatePostfix , false )
235
242
} catch ( error ) { console . log ( error ) ; }
236
243
244
+ try {
245
+ await adapter . ensureIndex ( 'Patient' , versionedSchema , [ 'updatedDate' ] , 'Patient' + indexUpdatedDatePostfix , false )
246
+ } catch ( error ) { console . log ( error ) ; }
247
+
248
+ try {
249
+ await adapter . ensureIndex ( 'Patient' , versionedSchema , [ 'createdAt' ] , 'Patient' + indexCreatedAtPostfix , false )
250
+ } catch ( error ) { console . log ( error ) ; }
251
+
252
+ try {
253
+ await adapter . ensureIndex ( 'Patient' , versionedSchema , [ 'logicalClock' ] , 'Patient' + indexLogicalClockPostfix , false )
254
+ } catch ( error ) { console . log ( error ) ; }
255
+
256
+ try {
257
+ await adapter . ensureIndex ( 'Patient_Audit' , schema , [ 'createdAt' ] , 'Patient_Audit' + indexCreatedAtPostfix , false )
258
+ } catch ( error ) { console . log ( error ) ; }
259
+
237
260
try {
238
261
await adapter . ensureIndex ( 'Contact' , versionedSchema , [ 'entityId' ] , 'Contact' + indexEntityIdPostfix , false )
239
262
} catch ( error ) { console . log ( error ) ; }
240
263
241
264
try {
242
265
await adapter . ensureIndex ( 'Contact' , versionedSchema , [ 'effectiveDate' ] , 'Contact' + indexEffectiveDatePostfix , false )
243
266
} catch ( error ) { console . log ( error ) ; }
267
+
268
+ try {
269
+ await adapter . ensureIndex ( 'Contact' , versionedSchema , [ 'updatedDate' ] , 'Contact' + indexUpdatedDatePostfix , false )
270
+ } catch ( error ) { console . log ( error ) ; }
271
+
272
+ try {
273
+ await adapter . ensureIndex ( 'Contact' , versionedSchema , [ 'createdAt' ] , 'Contact' + indexCreatedAtPostfix , false )
274
+ } catch ( error ) { console . log ( error ) ; }
275
+
276
+ try {
277
+ await adapter . ensureIndex ( 'Contact' , versionedSchema , [ 'logicalClock' ] , 'Contact' + indexLogicalClockPostfix , false )
278
+ } catch ( error ) { console . log ( error ) ; }
279
+
280
+ try {
281
+ await adapter . ensureIndex ( 'Contact_Audit' , schema , [ 'createdAt' ] , 'Contact_Audit' + indexCreatedAtPostfix , false )
282
+ } catch ( error ) { console . log ( error ) ; }
244
283
245
284
try {
246
285
await adapter . ensureIndex ( 'CarePlan' , versionedSchema , [ 'entityId' ] , 'CarePlan' + indexEntityIdPostfix , false )
@@ -250,6 +289,22 @@ async function createIndexes(){
250
289
await adapter . ensureIndex ( 'CarePlan' , versionedSchema , [ 'effectiveDate' ] , 'CarePlan' + indexEffectiveDatePostfix , false )
251
290
} catch ( error ) { console . log ( error ) ; }
252
291
292
+ try {
293
+ await adapter . ensureIndex ( 'CarePlan' , versionedSchema , [ 'updatedDate' ] , 'CarePlan' + indexUpdatedDatePostfix , false )
294
+ } catch ( error ) { console . log ( error ) ; }
295
+
296
+ try {
297
+ await adapter . ensureIndex ( 'CarePlan' , versionedSchema , [ 'createdAt' ] , 'CarePlan' + indexCreatedAtPostfix , false )
298
+ } catch ( error ) { console . log ( error ) ; }
299
+
300
+ try {
301
+ await adapter . ensureIndex ( 'CarePlan' , versionedSchema , [ 'logicalClock' ] , 'CarePlan' + indexLogicalClockPostfix , false )
302
+ } catch ( error ) { console . log ( error ) ; }
303
+
304
+ try {
305
+ await adapter . ensureIndex ( 'CarePlan_Audit' , schema , [ 'createdAt' ] , 'CarePlan_Audit' + indexCreatedAtPostfix , false )
306
+ } catch ( error ) { console . log ( error ) ; }
307
+
253
308
try {
254
309
await adapter . ensureIndex ( 'Task' , versionedSchema , [ 'entityId' ] , 'Task' + indexEntityIdPostfix , false )
255
310
} catch ( error ) { console . log ( error ) ; }
@@ -258,6 +313,22 @@ async function createIndexes(){
258
313
await adapter . ensureIndex ( 'Task' , versionedSchema , [ 'effectiveDate' ] , 'Task' + indexEffectiveDatePostfix , false )
259
314
} catch ( error ) { console . log ( error ) ; }
260
315
316
+ try {
317
+ await adapter . ensureIndex ( 'Task' , versionedSchema , [ 'updatedDate' ] , 'Task' + indexUpdatedDatePostfix , false )
318
+ } catch ( error ) { console . log ( error ) ; }
319
+
320
+ try {
321
+ await adapter . ensureIndex ( 'Task' , versionedSchema , [ 'createdAt' ] , 'Task' + indexCreatedAtPostfix , false )
322
+ } catch ( error ) { console . log ( error ) ; }
323
+
324
+ try {
325
+ await adapter . ensureIndex ( 'Task' , versionedSchema , [ 'logicalClock' ] , 'Task' + indexLogicalClockPostfix , false )
326
+ } catch ( error ) { console . log ( error ) ; }
327
+
328
+ try {
329
+ await adapter . ensureIndex ( 'Task_Audit' , schema , [ 'createdAt' ] , 'Task_Audit' + indexCreatedAtPostfix , false )
330
+ } catch ( error ) { console . log ( error ) ; }
331
+
261
332
try {
262
333
await adapter . ensureIndex ( 'HealthKitTask' , versionedSchema , [ 'entityId' ] , 'HealthKitTask' + indexEntityIdPostfix , false )
263
334
} catch ( error ) { console . log ( error ) ; }
@@ -266,22 +337,71 @@ async function createIndexes(){
266
337
await adapter . ensureIndex ( 'HealthKitTask' , versionedSchema , [ 'effectiveDate' ] , 'HealthKitTask' + indexEffectiveDatePostfix , false )
267
338
} catch ( error ) { console . log ( error ) ; }
268
339
340
+ try {
341
+ await adapter . ensureIndex ( 'HealthKitTask' , versionedSchema , [ 'updatedDate' ] , 'HealthKitTask' + indexUpdatedDatePostfix , false )
342
+ } catch ( error ) { console . log ( error ) ; }
343
+
344
+ try {
345
+ await adapter . ensureIndex ( 'HealthKitTask' , versionedSchema , [ 'createdAt' ] , 'HealthKitTask' + indexCreatedAtPostfix , false )
346
+ } catch ( error ) { console . log ( error ) ; }
347
+
348
+ try {
349
+ await adapter . ensureIndex ( 'HealthKitTask' , versionedSchema , [ 'logicalClock' ] , 'HealthKitTask' + indexLogicalClockPostfix , false )
350
+ } catch ( error ) { console . log ( error ) ; }
351
+
352
+ try {
353
+ await adapter . ensureIndex ( 'HealthKitTask_Audit' , schema , [ 'createdAt' ] , 'HealthKitTask_Audit' + indexCreatedAtPostfix , false )
354
+ } catch ( error ) { console . log ( error ) ; }
355
+
269
356
try {
270
357
await adapter . ensureIndex ( 'Outcome' , versionedSchema , [ 'entityId' ] , 'Outcome' + indexEntityIdPostfix , false )
271
358
} catch ( error ) { console . log ( error ) ; }
272
359
360
+ try {
361
+ await adapter . ensureIndex ( 'Outcome' , versionedSchema , [ 'updatedDate' ] , 'Outcome' + indexUpdatedDatePostfix , false )
362
+ } catch ( error ) { console . log ( error ) ; }
363
+
364
+ try {
365
+ await adapter . ensureIndex ( 'Outcome' , versionedSchema , [ 'createdAt' ] , 'Outcome' + indexCreatedAtPostfix , false )
366
+ } catch ( error ) { console . log ( error ) ; }
367
+
368
+ try {
369
+ await adapter . ensureIndex ( 'Outcome' , versionedSchema , [ 'logicalClock' ] , 'Outcome' + indexLogicalClockPostfix , false )
370
+ } catch ( error ) { console . log ( error ) ; }
371
+
372
+ try {
373
+ await adapter . ensureIndex ( 'Outcome_Audit' , schema , [ 'createdAt' ] , 'Outcome_Audit' + indexCreatedAtPostfix , false )
374
+ } catch ( error ) { console . log ( error ) ; }
375
+
273
376
try {
274
377
await adapter . ensureUniqueness ( 'Clock' , schema , [ 'uuid' ] )
275
378
} catch ( error ) { console . log ( error ) ; }
379
+
380
+ try {
381
+ await adapter . ensureIndex ( 'Clock' , schema , [ 'createdAt' ] , 'Outcome' + indexCreatedAtPostfix , false )
382
+ } catch ( error ) { console . log ( error ) ; }
383
+
384
+ try {
385
+ await adapter . ensureIndex ( 'Clock_Audit' , schema , [ 'createdAt' ] , 'Clock_Audit' + indexCreatedAtPostfix , false )
386
+ } catch ( error ) { console . log ( error ) ; }
387
+
388
+ try {
389
+ await adapter . ensureIndex ( '_User' , schema , [ 'createdAt' ] , '_User' + indexCreatedAtPostfix , false )
390
+ } catch ( error ) { console . log ( error ) ; }
391
+ }
392
+
393
+ if ( process . env . PARSE_USING_PARSECAREKIT == 'true' ) {
394
+ Parse . Cloud . run ( 'ensureClassDefaultFieldsForParseCareKit' ) ;
276
395
}
277
396
278
397
// If you are custimizing your own user schema, set PARSE_SET_USER_CLP to `false`
279
398
if ( process . env . PARSE_SET_USER_CLP == 'true' ) {
280
- //Fire after 5 seconds to allow _User class to be created
399
+ //Fire after 3 seconds to allow _User class to be created
281
400
setTimeout ( async function ( ) {
282
401
await Parse . Cloud . run ( 'setParseClassLevelPermissions' ) ;
283
402
if ( process . env . PARSE_USING_PARSECAREKIT == 'true' ) {
284
- Parse . Cloud . run ( 'setAuditClassLevelPermissions' ) ;
403
+ await Parse . Cloud . run ( 'setAuditClassLevelPermissions' ) ;
404
+ createIndexes ( ) ;
285
405
}
286
406
} , 3000 ) ;
287
407
}
0 commit comments