Skip to content

Commit

Permalink
Update default indexes (#32)
Browse files Browse the repository at this point in the history
* Update default indexes

* improve error handeling

* upgrad to Parse Server 5.0.0-alpha.16

* update compose image
  • Loading branch information
cbaker6 committed Jan 5, 2022
1 parent 5b7a390 commit 877606d
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.4'

services:
parse:
image: netreconlab/parse-hipaa:5.0.0-beta.3
image: netreconlab/parse-hipaa:5.0.0-alpha.16
environment:
PARSE_SERVER_APPLICATION_ID: E036A0C5-6829-4B40-9B3B-3E05F6DF32B2
PARSE_SERVER_PRIMARY_KEY: E2466756-93CF-4C05-BA44-FF5D9C34E99F
Expand Down
2 changes: 1 addition & 1 deletion parse/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM parseplatform/parse-server:5.0.0-beta.4
FROM parseplatform/parse-server:5.0.0-alpha.16

USER root
RUN apk add postgresql-client;
Expand Down
142 changes: 131 additions & 11 deletions parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ if(process.env.PARSE_SERVER_MOUNT_GRAPHQL == 'true'){
parseGraphQLServer.applyGraphQL(app); // Mounts the GraphQL API
}

// If you are not using ParseCareKit, set PARSE_USING_PARSECAREKIT to 0
if(process.env.PARSE_USING_PARSECAREKIT == 'true'){
createIndexes();
}

const host = process.env.HOST || '0.0.0.0';
const port = process.env.PORT || 1337;
const httpServer = require('http').createServer(app);
Expand All @@ -202,23 +197,35 @@ httpServer.listen(port, host, function() {
});

async function createIndexes(){
await Parse.Cloud.run('ensureClassDefaultFieldsForParseCareKit');
const adapter = api.config.databaseController.adapter;
const indexEntityIdPostfix = '_entityId';
const indexRemoteIdPostfix = '_remoteId';
const indexEffectiveDatePostfix = '_effectiveDate';

const indexUpdatedDatePostfix = '_updatedDate';
const indexCreatedAtPostfix = '_createdAt';
const indexLogicalClockPostfix = '_logicalClock';

const parseSchema = {
fields: {
createdAt: { type: 'Date' }
},
};

const schema = {
fields: {
uuid: { type: 'String' }
uuid: { type: 'String' },
createdAt: { type: 'Date' }
},
};

const versionedSchema = {
fields: {
entityId: { type: 'String' },
remoteID: { type: 'String' },
effectiveDate: { type: 'Date' }
effectiveDate: { type: 'Date' },
updatedDate: { type: 'Date' },
createdAt: { type: 'Date' },
logicalClock: { type: 'Number' }
},
};

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

try {
await adapter.ensureIndex('Patient', versionedSchema, ['updatedDate'], 'Patient'+indexUpdatedDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Patient', versionedSchema, ['createdAt'], 'Patient'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Patient', versionedSchema, ['logicalClock'], 'Patient'+indexLogicalClockPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Patient_Audit', schema, ['createdAt'], 'Patient_Audit'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Contact', versionedSchema, ['entityId'], 'Contact'+indexEntityIdPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Contact', versionedSchema, ['effectiveDate'], 'Contact'+indexEffectiveDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Contact', versionedSchema, ['updatedDate'], 'Contact'+indexUpdatedDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Contact', versionedSchema, ['createdAt'], 'Contact'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Contact', versionedSchema, ['logicalClock'], 'Contact'+indexLogicalClockPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Contact_Audit', schema, ['createdAt'], 'Contact_Audit'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

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

try {
await adapter.ensureIndex('CarePlan', versionedSchema, ['updatedDate'], 'CarePlan'+indexUpdatedDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('CarePlan', versionedSchema, ['createdAt'], 'CarePlan'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('CarePlan', versionedSchema, ['logicalClock'], 'CarePlan'+indexLogicalClockPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('CarePlan_Audit', schema, ['createdAt'], 'CarePlan_Audit'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Task', versionedSchema, ['entityId'], 'Task'+indexEntityIdPostfix, false)
} catch(error) { console.log(error); }
Expand All @@ -258,6 +313,22 @@ async function createIndexes(){
await adapter.ensureIndex('Task', versionedSchema, ['effectiveDate'], 'Task'+indexEffectiveDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Task', versionedSchema, ['updatedDate'], 'Task'+indexUpdatedDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Task', versionedSchema, ['createdAt'], 'Task'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Task', versionedSchema, ['logicalClock'], 'Task'+indexLogicalClockPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Task_Audit', schema, ['createdAt'], 'Task_Audit'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('HealthKitTask', versionedSchema, ['entityId'], 'HealthKitTask'+indexEntityIdPostfix, false)
} catch(error) { console.log(error); }
Expand All @@ -266,22 +337,71 @@ async function createIndexes(){
await adapter.ensureIndex('HealthKitTask', versionedSchema, ['effectiveDate'], 'HealthKitTask'+indexEffectiveDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('HealthKitTask', versionedSchema, ['updatedDate'], 'HealthKitTask'+indexUpdatedDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('HealthKitTask', versionedSchema, ['createdAt'], 'HealthKitTask'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('HealthKitTask', versionedSchema, ['logicalClock'], 'HealthKitTask'+indexLogicalClockPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('HealthKitTask_Audit', schema, ['createdAt'], 'HealthKitTask_Audit'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Outcome', versionedSchema, ['entityId'], 'Outcome'+indexEntityIdPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Outcome', versionedSchema, ['updatedDate'], 'Outcome'+indexUpdatedDatePostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Outcome', versionedSchema, ['createdAt'], 'Outcome'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Outcome', versionedSchema, ['logicalClock'], 'Outcome'+indexLogicalClockPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Outcome_Audit', schema, ['createdAt'], 'Outcome_Audit'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureUniqueness('Clock', schema, ['uuid'])
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Clock', schema, ['createdAt'], 'Outcome'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('Clock_Audit', schema, ['createdAt'], 'Clock_Audit'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }

try {
await adapter.ensureIndex('_User', schema, ['createdAt'], '_User'+indexCreatedAtPostfix, false)
} catch(error) { console.log(error); }
}

if(process.env.PARSE_USING_PARSECAREKIT == 'true'){
Parse.Cloud.run('ensureClassDefaultFieldsForParseCareKit');
}

// If you are custimizing your own user schema, set PARSE_SET_USER_CLP to `false`
if(process.env.PARSE_SET_USER_CLP == 'true'){
//Fire after 5 seconds to allow _User class to be created
//Fire after 3 seconds to allow _User class to be created
setTimeout(async function() {
await Parse.Cloud.run('setParseClassLevelPermissions');
if(process.env.PARSE_USING_PARSECAREKIT == 'true'){
Parse.Cloud.run('setAuditClassLevelPermissions');
await Parse.Cloud.run('setAuditClassLevelPermissions');
createIndexes();
}
}, 3000);
}
Expand Down

0 comments on commit 877606d

Please sign in to comment.