Skip to content

Commit 16d62ed

Browse files
committed
options
1 parent fb30e43 commit 16d62ed

File tree

5 files changed

+93
-41
lines changed

5 files changed

+93
-41
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,12 @@ export class MongoStorageAdapter implements StorageAdapter {
163163
'maxTimeMS',
164164
'disableIndexFieldValidation',
165165
'createIndexUsername',
166+
'createIndexUsernameCaseInsensitive',
166167
'createIndexEmail',
168+
'createIndexEmailCaseInsensitive',
167169
'createIndexEmailVerifyToken',
168170
'createIndexPasswordResetToken',
171+
'createIndexRoleName',
169172
]) {
170173
delete this._mongoOptions[key];
171174
}

src/Controllers/DatabaseController.js

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,50 +1738,66 @@ class DatabaseController {
17381738
await this.loadSchema().then(schema => schema.enforceClassExists('_Role'));
17391739
await this.loadSchema().then(schema => schema.enforceClassExists('_Idempotency'));
17401740

1741-
await this.adapter.ensureUniqueness('_User', requiredUserFields, ['username']).catch(error => {
1742-
logger.warn('Unable to ensure uniqueness for usernames: ', error);
1743-
throw error;
1744-
});
1741+
const databaseOptions = this.options.databaseOptions || {};
1742+
1743+
if (databaseOptions.createIndexUsername) {
1744+
await this.adapter.ensureUniqueness('_User', requiredUserFields, ['username']).catch(error => {
1745+
logger.warn('Unable to ensure uniqueness for usernames: ', error);
1746+
throw error;
1747+
});
1748+
}
17451749

17461750
if (!this.options.enableCollationCaseComparison) {
1751+
if (databaseOptions.createIndexUsernameCaseInsensitive) {
1752+
await this.adapter
1753+
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
1754+
.catch(error => {
1755+
logger.warn('Unable to create case insensitive username index: ', error);
1756+
throw error;
1757+
});
1758+
}
1759+
1760+
if (databaseOptions.createIndexEmailCaseInsensitive) {
1761+
await this.adapter
1762+
.ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true)
1763+
.catch(error => {
1764+
logger.warn('Unable to create case insensitive email index: ', error);
1765+
throw error;
1766+
});
1767+
}
1768+
}
1769+
1770+
if (databaseOptions.createIndexEmail) {
1771+
await this.adapter.ensureUniqueness('_User', requiredUserFields, ['email']).catch(error => {
1772+
logger.warn('Unable to ensure uniqueness for user email addresses: ', error);
1773+
throw error;
1774+
});
1775+
}
1776+
1777+
if (databaseOptions.createIndexEmailVerifyToken) {
17471778
await this.adapter
1748-
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
1779+
.ensureIndex('_User', requiredUserFields, ['_email_verify_token'], '_email_verify_token', false)
17491780
.catch(error => {
1750-
logger.warn('Unable to create case insensitive username index: ', error);
1781+
logger.warn('Unable to create index for email verification token: ', error);
17511782
throw error;
17521783
});
1784+
}
17531785

1786+
if (databaseOptions.createIndexPasswordResetToken) {
17541787
await this.adapter
1755-
.ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true)
1788+
.ensureIndex('_User', requiredUserFields, ['_perishable_token'], '_perishable_token', false)
17561789
.catch(error => {
1757-
logger.warn('Unable to create case insensitive email index: ', error);
1790+
logger.warn('Unable to create index for password reset token: ', error);
17581791
throw error;
17591792
});
17601793
}
17611794

1762-
await this.adapter.ensureUniqueness('_User', requiredUserFields, ['email']).catch(error => {
1763-
logger.warn('Unable to ensure uniqueness for user email addresses: ', error);
1764-
throw error;
1765-
});
1766-
1767-
await this.adapter
1768-
.ensureIndex('_User', requiredUserFields, ['_email_verify_token'], '_email_verify_token', false)
1769-
.catch(error => {
1770-
logger.warn('Unable to create index for email verification token: ', error);
1771-
throw error;
1772-
});
1773-
1774-
await this.adapter
1775-
.ensureIndex('_User', requiredUserFields, ['_perishable_token'], '_perishable_token', false)
1776-
.catch(error => {
1777-
logger.warn('Unable to create index for password reset token: ', error);
1795+
if (databaseOptions.createIndexRoleName) {
1796+
await this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name']).catch(error => {
1797+
logger.warn('Unable to ensure uniqueness for role name: ', error);
17781798
throw error;
17791799
});
1780-
1781-
await this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name']).catch(error => {
1782-
logger.warn('Unable to ensure uniqueness for role name: ', error);
1783-
throw error;
1784-
});
1800+
}
17851801

17861802
await this.adapter
17871803
.ensureUniqueness('_Idempotency', requiredIdempotencyFields, ['reqId'])

src/Options/Definitions.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,28 +1104,49 @@ module.exports.DatabaseOptions = {
11041104
createIndexEmail: {
11051105
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_EMAIL',
11061106
help:
1107-
'Set to `true` to automatically create indexes on the email field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F The automatically created index may change in the future to be optimized for the internal usage by Parse Server. Keep this in mind when manually creating this index.',
1107+
'Set to `true` to automatically create indexes on the email field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F When setting this option to `false` to manually create the index, keep in mind that the otherwise automatically created index may change in the future to be optimized for the internal usage by Parse Server.',
1108+
action: parsers.booleanParser,
1109+
default: true,
1110+
},
1111+
createIndexEmailCaseInsensitive: {
1112+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_EMAIL_CASE_INSENSITIVE',
1113+
help:
1114+
'Set to `true` to automatically create a case-insensitive index on the email field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F When setting this option to `false` to manually create the index, keep in mind that the otherwise automatically created index may change in the future to be optimized for the internal usage by Parse Server.',
11081115
action: parsers.booleanParser,
11091116
default: true,
11101117
},
11111118
createIndexEmailVerifyToken: {
11121119
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_EMAIL_VERIFY_TOKEN',
11131120
help:
1114-
'Set to `true` to automatically create an index on the _email_verify_token field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F The automatically created index may change in the future to be optimized for the internal usage by Parse Server. Keep this in mind when manually creating this index.',
1121+
'Set to `true` to automatically create an index on the _email_verify_token field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F When setting this option to `false` to manually create the index, keep in mind that the otherwise automatically created index may change in the future to be optimized for the internal usage by Parse Server.',
11151122
action: parsers.booleanParser,
11161123
default: true,
11171124
},
11181125
createIndexPasswordResetToken: {
11191126
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_PASSWORD_RESET_TOKEN',
11201127
help:
1121-
'Set to `true` to automatically create an index on the _perishable_token field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F The automatically created index may change in the future to be optimized for the internal usage by Parse Server. Keep this in mind when manually creating this index.',
1128+
'Set to `true` to automatically create an index on the _perishable_token field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F When setting this option to `false` to manually create the index, keep in mind that the otherwise automatically created index may change in the future to be optimized for the internal usage by Parse Server.',
1129+
action: parsers.booleanParser,
1130+
default: true,
1131+
},
1132+
createIndexRoleName: {
1133+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_ROLE_NAME',
1134+
help:
1135+
'Set to `true` to automatically create a unique index on the name field of the _Role collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F When setting this option to `false` to manually create the index, keep in mind that the otherwise automatically created index may change in the future to be optimized for the internal usage by Parse Server.',
11221136
action: parsers.booleanParser,
11231137
default: true,
11241138
},
11251139
createIndexUsername: {
11261140
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USERNAME',
11271141
help:
1128-
'Set to `true` to automatically create indexes on the username field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F The automatically created index may change in the future to be optimized for the internal usage by Parse Server. Keep this in mind when manually creating this index.',
1142+
'Set to `true` to automatically create indexes on the username field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F When setting this option to `false` to manually create the index, keep in mind that the otherwise automatically created index may change in the future to be optimized for the internal usage by Parse Server.',
1143+
action: parsers.booleanParser,
1144+
default: true,
1145+
},
1146+
createIndexUsernameCaseInsensitive: {
1147+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USERNAME_CASE_INSENSITIVE',
1148+
help:
1149+
'Set to `true` to automatically create a case-insensitive index on the username field of the _User collection on server start. Set to `false` to skip index creation. Default is `true`.<br><br>\u26A0\uFE0F When setting this option to `false` to manually create the index, keep in mind that the otherwise automatically created index may change in the future to be optimized for the internal usage by Parse Server.',
11291150
action: parsers.booleanParser,
11301151
default: true,
11311152
},

src/Options/docs.js

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)