Skip to content

Commit 877606d

Browse files
authored
Update default indexes (#32)
* Update default indexes * improve error handeling * upgrad to Parse Server 5.0.0-alpha.16 * update compose image
1 parent 5b7a390 commit 877606d

File tree

3 files changed

+133
-13
lines changed

3 files changed

+133
-13
lines changed

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.4'
22

33
services:
44
parse:
5-
image: netreconlab/parse-hipaa:5.0.0-beta.3
5+
image: netreconlab/parse-hipaa:5.0.0-alpha.16
66
environment:
77
PARSE_SERVER_APPLICATION_ID: E036A0C5-6829-4B40-9B3B-3E05F6DF32B2
88
PARSE_SERVER_PRIMARY_KEY: E2466756-93CF-4C05-BA44-FF5D9C34E99F

parse/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM parseplatform/parse-server:5.0.0-beta.4
1+
FROM parseplatform/parse-server:5.0.0-alpha.16
22

33
USER root
44
RUN apk add postgresql-client;

parse/index.js

+131-11
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ if(process.env.PARSE_SERVER_MOUNT_GRAPHQL == 'true'){
185185
parseGraphQLServer.applyGraphQL(app); // Mounts the GraphQL API
186186
}
187187

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-
193188
const host = process.env.HOST || '0.0.0.0';
194189
const port = process.env.PORT || 1337;
195190
const httpServer = require('http').createServer(app);
@@ -202,23 +197,35 @@ httpServer.listen(port, host, function() {
202197
});
203198

204199
async function createIndexes(){
205-
await Parse.Cloud.run('ensureClassDefaultFieldsForParseCareKit');
206200
const adapter = api.config.databaseController.adapter;
207201
const indexEntityIdPostfix = '_entityId';
208202
const indexRemoteIdPostfix = '_remoteId';
209203
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+
211214
const schema = {
212215
fields: {
213-
uuid: { type: 'String' }
216+
uuid: { type: 'String' },
217+
createdAt: { type: 'Date' }
214218
},
215219
};
216220

217221
const versionedSchema = {
218222
fields: {
219223
entityId: { type: 'String' },
220224
remoteID: { type: 'String' },
221-
effectiveDate: { type: 'Date' }
225+
effectiveDate: { type: 'Date' },
226+
updatedDate: { type: 'Date' },
227+
createdAt: { type: 'Date' },
228+
logicalClock: { type: 'Number' }
222229
},
223230
};
224231

@@ -234,13 +241,45 @@ async function createIndexes(){
234241
await adapter.ensureIndex('Patient', versionedSchema, ['effectiveDate'], 'Patient'+indexEffectiveDatePostfix, false)
235242
} catch(error) { console.log(error); }
236243

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+
237260
try {
238261
await adapter.ensureIndex('Contact', versionedSchema, ['entityId'], 'Contact'+indexEntityIdPostfix, false)
239262
} catch(error) { console.log(error); }
240263

241264
try {
242265
await adapter.ensureIndex('Contact', versionedSchema, ['effectiveDate'], 'Contact'+indexEffectiveDatePostfix, false)
243266
} 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); }
244283

245284
try {
246285
await adapter.ensureIndex('CarePlan', versionedSchema, ['entityId'], 'CarePlan'+indexEntityIdPostfix, false)
@@ -250,6 +289,22 @@ async function createIndexes(){
250289
await adapter.ensureIndex('CarePlan', versionedSchema, ['effectiveDate'], 'CarePlan'+indexEffectiveDatePostfix, false)
251290
} catch(error) { console.log(error); }
252291

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+
253308
try {
254309
await adapter.ensureIndex('Task', versionedSchema, ['entityId'], 'Task'+indexEntityIdPostfix, false)
255310
} catch(error) { console.log(error); }
@@ -258,6 +313,22 @@ async function createIndexes(){
258313
await adapter.ensureIndex('Task', versionedSchema, ['effectiveDate'], 'Task'+indexEffectiveDatePostfix, false)
259314
} catch(error) { console.log(error); }
260315

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+
261332
try {
262333
await adapter.ensureIndex('HealthKitTask', versionedSchema, ['entityId'], 'HealthKitTask'+indexEntityIdPostfix, false)
263334
} catch(error) { console.log(error); }
@@ -266,22 +337,71 @@ async function createIndexes(){
266337
await adapter.ensureIndex('HealthKitTask', versionedSchema, ['effectiveDate'], 'HealthKitTask'+indexEffectiveDatePostfix, false)
267338
} catch(error) { console.log(error); }
268339

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+
269356
try {
270357
await adapter.ensureIndex('Outcome', versionedSchema, ['entityId'], 'Outcome'+indexEntityIdPostfix, false)
271358
} catch(error) { console.log(error); }
272359

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+
273376
try {
274377
await adapter.ensureUniqueness('Clock', schema, ['uuid'])
275378
} 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');
276395
}
277396

278397
// If you are custimizing your own user schema, set PARSE_SET_USER_CLP to `false`
279398
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
281400
setTimeout(async function() {
282401
await Parse.Cloud.run('setParseClassLevelPermissions');
283402
if(process.env.PARSE_USING_PARSECAREKIT == 'true'){
284-
Parse.Cloud.run('setAuditClassLevelPermissions');
403+
await Parse.Cloud.run('setAuditClassLevelPermissions');
404+
createIndexes();
285405
}
286406
}, 3000);
287407
}

0 commit comments

Comments
 (0)