@@ -154,6 +154,10 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
154
154
objectId : { type : 'String' } ,
155
155
username : { type : 'String' } ,
156
156
email : { type : 'String' } ,
157
+ emailVerified : { type : 'Boolean' } ,
158
+ createdAt : { type : 'Date' } ,
159
+ updatedAt : { type : 'Date' } ,
160
+ authData : { type : 'Object' } ,
157
161
} ,
158
162
} ;
159
163
const client = adapter . _client ;
@@ -173,77 +177,66 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
173
177
const caseInsensitiveData = 'bugs' ;
174
178
const originalQuery = 'SELECT * FROM $1:name WHERE lower($2:name)=lower($3)' ;
175
179
const analyzedExplainQuery = adapter . createExplainableQuery ( originalQuery , true ) ;
176
- await client
177
- . one ( analyzedExplainQuery , [ tableName , 'objectId' , caseInsensitiveData ] )
178
- . then ( explained => {
179
- const preIndexPlan = explained ;
180
-
181
- preIndexPlan [ 'QUERY PLAN' ] . forEach ( element => {
182
- //Make sure search returned with only 1 result
183
- expect ( element . Plan [ 'Actual Rows' ] ) . toBe ( 1 ) ;
184
- expect ( element . Plan [ 'Node Type' ] ) . toBe ( 'Seq Scan' ) ;
185
- } ) ;
186
- const indexName = 'test_case_insensitive_column' ;
187
-
188
- adapter . ensureIndex ( tableName , schema , [ 'objectId' ] , indexName , true ) . then ( ( ) => {
189
- client
190
- . one ( analyzedExplainQuery , [ tableName , 'objectId' , caseInsensitiveData ] )
191
- . then ( explained => {
192
- const postIndexPlan = explained ;
193
-
194
- postIndexPlan [ 'QUERY PLAN' ] . forEach ( element => {
195
- //Make sure search returned with only 1 result
196
- expect ( element . Plan [ 'Actual Rows' ] ) . toBe ( 1 ) ;
197
- //Should not be a sequential scan
198
- expect ( element . Plan [ 'Node Type' ] ) . not . toContain ( 'Seq Scan' ) ;
199
-
200
- //Should be using the index created for this
201
- element . Plan . Plans . forEach ( innerElement => {
202
- expect ( innerElement [ 'Index Name' ] ) . toBe ( indexName ) ;
203
- } ) ;
204
- } ) ;
205
-
206
- //These are the same query so should be the same size
207
- for ( let i = 0 ; i < preIndexPlan [ 'QUERY PLAN' ] . length ; i ++ ) {
208
- //Sequential should take more time to execute than indexed
209
- expect ( preIndexPlan [ 'QUERY PLAN' ] [ i ] [ 'Execution Time' ] ) . toBeGreaterThan (
210
- postIndexPlan [ 'QUERY PLAN' ] [ i ] [ 'Execution Time' ]
211
- ) ;
212
- }
213
-
214
- //Test explaining without analyzing
215
- const basicExplainQuery = adapter . createExplainableQuery ( originalQuery ) ;
216
- client
217
- . one ( basicExplainQuery , [ tableName , 'objectId' , caseInsensitiveData ] )
218
- . then ( explained => {
219
- explained [ 'QUERY PLAN' ] . forEach ( element => {
220
- //Check that basic query plans isn't a sequential scan
221
- expect ( element . Plan [ 'Node Type' ] ) . not . toContain ( 'Seq Scan' ) ;
222
-
223
- //Basic query plans shouldn't have an execution time
224
- expect ( element [ 'Execution Time' ] ) . toBeUndefined ( ) ;
225
- } ) ;
226
- } ) ;
227
- } ) ;
228
- } ) ;
229
- } )
230
- . catch ( error => {
231
- // Query on non existing table, don't crash
232
- if ( error . code !== '42P01' ) {
233
- throw error ;
234
- }
235
- return [ ] ;
180
+ const preIndexPlan = await client . one ( analyzedExplainQuery , [
181
+ tableName ,
182
+ 'objectId' ,
183
+ caseInsensitiveData ,
184
+ ] ) ;
185
+ preIndexPlan [ 'QUERY PLAN' ] . forEach ( element => {
186
+ //Make sure search returned with only 1 result
187
+ expect ( element . Plan [ 'Actual Rows' ] ) . toBe ( 1 ) ;
188
+ expect ( element . Plan [ 'Node Type' ] ) . toBe ( 'Seq Scan' ) ;
189
+ } ) ;
190
+ const indexName = 'test_case_insensitive_column' ;
191
+ await adapter . ensureIndex ( tableName , schema , [ 'objectId' ] , indexName , true ) ;
192
+
193
+ const postIndexPlan = await client . one ( analyzedExplainQuery , [
194
+ tableName ,
195
+ 'objectId' ,
196
+ caseInsensitiveData ,
197
+ ] ) ;
198
+ postIndexPlan [ 'QUERY PLAN' ] . forEach ( element => {
199
+ //Make sure search returned with only 1 result
200
+ expect ( element . Plan [ 'Actual Rows' ] ) . toBe ( 1 ) ;
201
+ //Should not be a sequential scan
202
+ expect ( element . Plan [ 'Node Type' ] ) . not . toContain ( 'Seq Scan' ) ;
203
+
204
+ //Should be using the index created for this
205
+ element . Plan . Plans . forEach ( innerElement => {
206
+ expect ( innerElement [ 'Index Name' ] ) . toBe ( indexName ) ;
236
207
} ) ;
208
+ } ) ;
209
+
210
+ //These are the same query so should be the same size
211
+ for ( let i = 0 ; i < preIndexPlan [ 'QUERY PLAN' ] . length ; i ++ ) {
212
+ //Sequential should take more time to execute than indexed
213
+ expect ( preIndexPlan [ 'QUERY PLAN' ] [ i ] [ 'Execution Time' ] ) . toBeGreaterThan (
214
+ postIndexPlan [ 'QUERY PLAN' ] [ i ] [ 'Execution Time' ]
215
+ ) ;
216
+ }
217
+ //Test explaining without analyzing
218
+ const basicExplainQuery = adapter . createExplainableQuery ( originalQuery ) ;
219
+ const explained = await client . one ( basicExplainQuery , [
220
+ tableName ,
221
+ 'objectId' ,
222
+ caseInsensitiveData ,
223
+ ] ) ;
224
+ explained [ 'QUERY PLAN' ] . forEach ( element => {
225
+ //Check that basic query plans isn't a sequential scan
226
+ expect ( element . Plan [ 'Node Type' ] ) . not . toContain ( 'Seq Scan' ) ;
227
+
228
+ //Basic query plans shouldn't have an execution time
229
+ expect ( element [ 'Execution Time' ] ) . toBeUndefined ( ) ;
230
+ } ) ;
231
+ await dropTable ( client , tableName ) ;
237
232
} ) ;
238
233
239
234
it ( 'should use index for caseInsensitive query' , async ( ) => {
240
235
const tableName = '_User' ;
241
- await adapter . deleteClass ( tableName ) ;
242
- await reconfigureServer ( ) ;
243
236
244
237
const user = new Parse . User ( ) ;
245
- user . set ( 'username' , 'Bugs ' ) ;
246
- user . set ( 'password' , 'Bunny ' ) ;
238
+ user . set ( 'username' , 'Elmer ' ) ;
239
+ user . set ( 'password' , 'Fudd ' ) ;
247
240
await user . signUp ( ) ;
248
241
const database = Config . get ( Parse . applicationId ) . database ;
249
242
@@ -253,7 +246,7 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
253
246
'INSERT INTO $1:name ($2:name, $3:name) SELECT gen_random_uuid(), gen_random_uuid() FROM generate_series(1,5000)' ,
254
247
[ tableName , 'objectId' , 'username' ]
255
248
) ;
256
- const caseInsensitiveData = 'bugs ' ;
249
+ const caseInsensitiveData = 'elmer ' ;
257
250
const fieldToSearch = 'username' ;
258
251
//Check using find method for Parse
259
252
const preIndexPlan = await database . find (
@@ -265,7 +258,7 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
265
258
preIndexPlan . forEach ( element => {
266
259
element [ 'QUERY PLAN' ] . forEach ( innerElement => {
267
260
//Check that basic query plans isn't a sequential scan, be careful as find uses "any" to query
268
- expect ( innerElement . Plan [ 'Node Type' ] ) . toBe ( 'Bitmap Heap Scan' ) ;
261
+ expect ( innerElement . Plan [ 'Node Type' ] ) . toBe ( 'Seq Scan' ) ;
269
262
//Basic query plans shouldn't have an execution time
270
263
expect ( innerElement [ 'Execution Time' ] ) . toBeUndefined ( ) ;
271
264
} ) ;
@@ -296,8 +289,8 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
296
289
it ( 'should use index for caseInsensitive query using default indexname' , async ( ) => {
297
290
const tableName = '_User' ;
298
291
const user = new Parse . User ( ) ;
299
- user . set ( 'username' , 'Bugs ' ) ;
300
- user . set ( 'password' , 'Bunny ' ) ;
292
+ user . set ( 'username' , 'Tweety ' ) ;
293
+ user . set ( 'password' , 'Bird ' ) ;
301
294
await user . signUp ( ) ;
302
295
const database = Config . get ( Parse . applicationId ) . database ;
303
296
const fieldToSearch = 'username' ;
@@ -312,7 +305,7 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
312
305
[ tableName , 'objectId' , 'username' ]
313
306
) ;
314
307
315
- const caseInsensitiveData = 'buGs ' ;
308
+ const caseInsensitiveData = 'tweeTy ' ;
316
309
//Check using find method for Parse
317
310
const indexPlan = await database . find (
318
311
tableName ,
0 commit comments