Skip to content

Commit 1575165

Browse files
committed
add class to index option
1 parent ff87e1e commit 1575165

File tree

6 files changed

+87
-67
lines changed

6 files changed

+87
-67
lines changed

spec/MongoStorageAdapter.spec.js

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -664,121 +664,121 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
664664
return await adapter.database.collection(collectionName).indexes();
665665
}
666666

667-
it('should skip username index when createIndexUsername is false', async () => {
667+
it('should skip username index when createIndexUserUsername is false', async () => {
668668
await reconfigureServer({
669669
databaseAdapter: undefined,
670670
databaseURI,
671-
databaseOptions: { createIndexUsername: false },
671+
databaseOptions: { createIndexUserUsername: false },
672672
});
673673
const indexes = await getIndexes('_User');
674674
expect(indexes.find(idx => idx.name === 'username_1')).toBeUndefined();
675675
});
676676

677-
it('should create username index when createIndexUsername is true', async () => {
677+
it('should create username index when createIndexUserUsername is true', async () => {
678678
await reconfigureServer({
679679
databaseAdapter: undefined,
680680
databaseURI,
681-
databaseOptions: { createIndexUsername: true },
681+
databaseOptions: { createIndexUserUsername: true },
682682
});
683683
const indexes = await getIndexes('_User');
684684
expect(indexes.find(idx => idx.name === 'username_1')).toBeDefined();
685685
});
686686

687-
it('should skip case-insensitive username index when createIndexUsernameCaseInsensitive is false', async () => {
687+
it('should skip case-insensitive username index when createIndexUserUsernameCaseInsensitive is false', async () => {
688688
await reconfigureServer({
689689
databaseAdapter: undefined,
690690
databaseURI,
691-
databaseOptions: { createIndexUsernameCaseInsensitive: false },
691+
databaseOptions: { createIndexUserUsernameCaseInsensitive: false },
692692
});
693693
const indexes = await getIndexes('_User');
694694
expect(indexes.find(idx => idx.name === 'case_insensitive_username')).toBeUndefined();
695695
});
696696

697-
it('should create case-insensitive username index when createIndexUsernameCaseInsensitive is true', async () => {
697+
it('should create case-insensitive username index when createIndexUserUsernameCaseInsensitive is true', async () => {
698698
await reconfigureServer({
699699
databaseAdapter: undefined,
700700
databaseURI,
701-
databaseOptions: { createIndexUsernameCaseInsensitive: true },
701+
databaseOptions: { createIndexUserUsernameCaseInsensitive: true },
702702
});
703703
const indexes = await getIndexes('_User');
704704
expect(indexes.find(idx => idx.name === 'case_insensitive_username')).toBeDefined();
705705
});
706706

707-
it('should skip email index when createIndexEmail is false', async () => {
707+
it('should skip email index when createIndexUserEmail is false', async () => {
708708
await reconfigureServer({
709709
databaseAdapter: undefined,
710710
databaseURI,
711-
databaseOptions: { createIndexEmail: false },
711+
databaseOptions: { createIndexUserEmail: false },
712712
});
713713
const indexes = await getIndexes('_User');
714714
expect(indexes.find(idx => idx.name === 'email_1')).toBeUndefined();
715715
});
716716

717-
it('should create email index when createIndexEmail is true', async () => {
717+
it('should create email index when createIndexUserEmail is true', async () => {
718718
await reconfigureServer({
719719
databaseAdapter: undefined,
720720
databaseURI,
721-
databaseOptions: { createIndexEmail: true },
721+
databaseOptions: { createIndexUserEmail: true },
722722
});
723723
const indexes = await getIndexes('_User');
724724
expect(indexes.find(idx => idx.name === 'email_1')).toBeDefined();
725725
});
726726

727-
it('should skip case-insensitive email index when createIndexEmailCaseInsensitive is false', async () => {
727+
it('should skip case-insensitive email index when createIndexUserEmailCaseInsensitive is false', async () => {
728728
await reconfigureServer({
729729
databaseAdapter: undefined,
730730
databaseURI,
731-
databaseOptions: { createIndexEmailCaseInsensitive: false },
731+
databaseOptions: { createIndexUserEmailCaseInsensitive: false },
732732
});
733733
const indexes = await getIndexes('_User');
734734
expect(indexes.find(idx => idx.name === 'case_insensitive_email')).toBeUndefined();
735735
});
736736

737-
it('should create case-insensitive email index when createIndexEmailCaseInsensitive is true', async () => {
737+
it('should create case-insensitive email index when createIndexUserEmailCaseInsensitive is true', async () => {
738738
await reconfigureServer({
739739
databaseAdapter: undefined,
740740
databaseURI,
741-
databaseOptions: { createIndexEmailCaseInsensitive: true },
741+
databaseOptions: { createIndexUserEmailCaseInsensitive: true },
742742
});
743743
const indexes = await getIndexes('_User');
744744
expect(indexes.find(idx => idx.name === 'case_insensitive_email')).toBeDefined();
745745
});
746746

747-
it('should skip email verify token index when createIndexEmailVerifyToken is false', async () => {
747+
it('should skip email verify token index when createIndexUserEmailVerifyToken is false', async () => {
748748
await reconfigureServer({
749749
databaseAdapter: undefined,
750750
databaseURI,
751-
databaseOptions: { createIndexEmailVerifyToken: false },
751+
databaseOptions: { createIndexUserEmailVerifyToken: false },
752752
});
753753
const indexes = await getIndexes('_User');
754754
expect(indexes.find(idx => idx.name === '_email_verify_token' || idx.name === '_email_verify_token_1')).toBeUndefined();
755755
});
756756

757-
it('should create email verify token index when createIndexEmailVerifyToken is true', async () => {
757+
it('should create email verify token index when createIndexUserEmailVerifyToken is true', async () => {
758758
await reconfigureServer({
759759
databaseAdapter: undefined,
760760
databaseURI,
761-
databaseOptions: { createIndexEmailVerifyToken: true },
761+
databaseOptions: { createIndexUserEmailVerifyToken: true },
762762
});
763763
const indexes = await getIndexes('_User');
764764
expect(indexes.find(idx => idx.name === '_email_verify_token' || idx.name === '_email_verify_token_1')).toBeDefined();
765765
});
766766

767-
it('should skip password reset token index when createIndexPasswordResetToken is false', async () => {
767+
it('should skip password reset token index when createIndexUserPasswordResetToken is false', async () => {
768768
await reconfigureServer({
769769
databaseAdapter: undefined,
770770
databaseURI,
771-
databaseOptions: { createIndexPasswordResetToken: false },
771+
databaseOptions: { createIndexUserPasswordResetToken: false },
772772
});
773773
const indexes = await getIndexes('_User');
774774
expect(indexes.find(idx => idx.name === '_perishable_token' || idx.name === '_perishable_token_1')).toBeUndefined();
775775
});
776776

777-
it('should create password reset token index when createIndexPasswordResetToken is true', async () => {
777+
it('should create password reset token index when createIndexUserPasswordResetToken is true', async () => {
778778
await reconfigureServer({
779779
databaseAdapter: undefined,
780780
databaseURI,
781-
databaseOptions: { createIndexPasswordResetToken: true },
781+
databaseOptions: { createIndexUserPasswordResetToken: true },
782782
});
783783
const indexes = await getIndexes('_User');
784784
expect(indexes.find(idx => idx.name === '_perishable_token' || idx.name === '_perishable_token_1')).toBeDefined();
@@ -803,5 +803,25 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
803803
const indexes = await getIndexes('_Role');
804804
expect(indexes.find(idx => idx.name === 'name_1')).toBeDefined();
805805
});
806+
807+
it('should create all indexes by default when options are undefined', async () => {
808+
await reconfigureServer({
809+
databaseAdapter: undefined,
810+
databaseURI,
811+
databaseOptions: {},
812+
});
813+
814+
const userIndexes = await getIndexes('_User');
815+
const roleIndexes = await getIndexes('_Role');
816+
817+
// Verify all indexes are created with default behavior (backward compatibility)
818+
expect(userIndexes.find(idx => idx.name === 'username_1')).toBeDefined();
819+
expect(userIndexes.find(idx => idx.name === 'case_insensitive_username')).toBeDefined();
820+
expect(userIndexes.find(idx => idx.name === 'email_1')).toBeDefined();
821+
expect(userIndexes.find(idx => idx.name === 'case_insensitive_email')).toBeDefined();
822+
expect(userIndexes.find(idx => idx.name === '_email_verify_token' || idx.name === '_email_verify_token_1')).toBeDefined();
823+
expect(userIndexes.find(idx => idx.name === '_perishable_token' || idx.name === '_perishable_token_1')).toBeDefined();
824+
expect(roleIndexes.find(idx => idx.name === 'name_1')).toBeDefined();
825+
});
806826
});
807827
});

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ export class MongoStorageAdapter implements StorageAdapter {
162162
'schemaCacheTtl',
163163
'maxTimeMS',
164164
'disableIndexFieldValidation',
165-
'createIndexUsername',
166-
'createIndexUsernameCaseInsensitive',
167-
'createIndexEmail',
168-
'createIndexEmailCaseInsensitive',
169-
'createIndexEmailVerifyToken',
170-
'createIndexPasswordResetToken',
165+
'createIndexUserUsername',
166+
'createIndexUserUsernameCaseInsensitive',
167+
'createIndexUserEmail',
168+
'createIndexUserEmailCaseInsensitive',
169+
'createIndexUserEmailVerifyToken',
170+
'createIndexUserPasswordResetToken',
171171
'createIndexRoleName',
172172
]) {
173173
delete this._mongoOptions[key];

src/Controllers/DatabaseController.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,15 +1740,15 @@ class DatabaseController {
17401740

17411741
const databaseOptions = this.options.databaseOptions || {};
17421742

1743-
if (databaseOptions.createIndexUsername !== false) {
1743+
if (databaseOptions.createIndexUserUsername !== false) {
17441744
await this.adapter.ensureUniqueness('_User', requiredUserFields, ['username']).catch(error => {
17451745
logger.warn('Unable to ensure uniqueness for usernames: ', error);
17461746
throw error;
17471747
});
17481748
}
17491749

17501750
if (!this.options.enableCollationCaseComparison) {
1751-
if (databaseOptions.createIndexUsernameCaseInsensitive !== false) {
1751+
if (databaseOptions.createIndexUserUsernameCaseInsensitive !== false) {
17521752
await this.adapter
17531753
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
17541754
.catch(error => {
@@ -1757,7 +1757,7 @@ class DatabaseController {
17571757
});
17581758
}
17591759

1760-
if (databaseOptions.createIndexEmailCaseInsensitive !== false) {
1760+
if (databaseOptions.createIndexUserEmailCaseInsensitive !== false) {
17611761
await this.adapter
17621762
.ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true)
17631763
.catch(error => {
@@ -1767,14 +1767,14 @@ class DatabaseController {
17671767
}
17681768
}
17691769

1770-
if (databaseOptions.createIndexEmail !== false) {
1770+
if (databaseOptions.createIndexUserEmail !== false) {
17711771
await this.adapter.ensureUniqueness('_User', requiredUserFields, ['email']).catch(error => {
17721772
logger.warn('Unable to ensure uniqueness for user email addresses: ', error);
17731773
throw error;
17741774
});
17751775
}
17761776

1777-
if (databaseOptions.createIndexEmailVerifyToken !== false) {
1777+
if (databaseOptions.createIndexUserEmailVerifyToken !== false) {
17781778
await this.adapter
17791779
.ensureIndex('_User', requiredUserFields, ['_email_verify_token'], '_email_verify_token', false)
17801780
.catch(error => {
@@ -1783,7 +1783,7 @@ class DatabaseController {
17831783
});
17841784
}
17851785

1786-
if (databaseOptions.createIndexPasswordResetToken !== false) {
1786+
if (databaseOptions.createIndexUserPasswordResetToken !== false) {
17871787
await this.adapter
17881788
.ensureIndex('_User', requiredUserFields, ['_perishable_token'], '_perishable_token', false)
17891789
.catch(error => {

src/Options/Definitions.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,50 +1101,50 @@ module.exports.DatabaseOptions = {
11011101
'The MongoDB driver option to specify the amount of time, in milliseconds, to wait to establish a single TCP socket connection to the server before raising an error. Specifying 0 disables the connection timeout.',
11021102
action: parsers.numberParser('connectTimeoutMS'),
11031103
},
1104-
createIndexEmail: {
1105-
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_EMAIL',
1104+
createIndexRoleName: {
1105+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_ROLE_NAME',
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 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.',
1107+
'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.',
11081108
action: parsers.booleanParser,
11091109
default: true,
11101110
},
1111-
createIndexEmailCaseInsensitive: {
1112-
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_EMAIL_CASE_INSENSITIVE',
1111+
createIndexUserEmail: {
1112+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USER_EMAIL',
11131113
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.',
1114+
'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.',
11151115
action: parsers.booleanParser,
11161116
default: true,
11171117
},
1118-
createIndexEmailVerifyToken: {
1119-
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_EMAIL_VERIFY_TOKEN',
1118+
createIndexUserEmailCaseInsensitive: {
1119+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USER_EMAIL_CASE_INSENSITIVE',
11201120
help:
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.',
1121+
'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.',
11221122
action: parsers.booleanParser,
11231123
default: true,
11241124
},
1125-
createIndexPasswordResetToken: {
1126-
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_PASSWORD_RESET_TOKEN',
1125+
createIndexUserEmailVerifyToken: {
1126+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USER_EMAIL_VERIFY_TOKEN',
11271127
help:
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.',
1128+
'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.',
11291129
action: parsers.booleanParser,
11301130
default: true,
11311131
},
1132-
createIndexRoleName: {
1133-
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_ROLE_NAME',
1132+
createIndexUserPasswordResetToken: {
1133+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USER_PASSWORD_RESET_TOKEN',
11341134
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.',
1135+
'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.',
11361136
action: parsers.booleanParser,
11371137
default: true,
11381138
},
1139-
createIndexUsername: {
1140-
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USERNAME',
1139+
createIndexUserUsername: {
1140+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USER_USERNAME',
11411141
help:
11421142
'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.',
11431143
action: parsers.booleanParser,
11441144
default: true,
11451145
},
1146-
createIndexUsernameCaseInsensitive: {
1147-
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USERNAME_CASE_INSENSITIVE',
1146+
createIndexUserUsernameCaseInsensitive: {
1147+
env: 'PARSE_SERVER_DATABASE_CREATE_INDEX_USER_USERNAME_CASE_INSENSITIVE',
11481148
help:
11491149
'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.',
11501150
action: parsers.booleanParser,

0 commit comments

Comments
 (0)