Allow creation of indices on default fields (#4738)
* Allow creation of indexes on default fields * Update test * Try to address flaky cache test
This commit is contained in:
committed by
Tyler Brock
parent
b1017ac17c
commit
04588bccb9
@@ -28,7 +28,7 @@ describe('InMemoryCache', function() {
|
|||||||
let value = cache.get(KEY);
|
let value = cache.get(KEY);
|
||||||
expect(value).toEqual(VALUE);
|
expect(value).toEqual(VALUE);
|
||||||
|
|
||||||
wait(BASE_TTL.ttl * 2).then(() => {
|
wait(BASE_TTL.ttl * 10).then(() => {
|
||||||
value = cache.get(KEY)
|
value = cache.get(KEY)
|
||||||
expect(value).toEqual(null);
|
expect(value).toEqual(null);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -1852,6 +1852,29 @@ describe('schemas', () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can create index on default field', done => {
|
||||||
|
request.post({
|
||||||
|
url: 'http://localhost:8378/1/schemas/NewClass',
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
json: true,
|
||||||
|
body: {},
|
||||||
|
}, () => {
|
||||||
|
request.put({
|
||||||
|
url: 'http://localhost:8378/1/schemas/NewClass',
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
json: true,
|
||||||
|
body: {
|
||||||
|
indexes: {
|
||||||
|
name1: { createdAt: 1},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (error, response, body) => {
|
||||||
|
expect(body.indexes.name1).toEqual({ createdAt: 1});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
it('cannot create compound index if field does not exist', done => {
|
it('cannot create compound index if field does not exist', done => {
|
||||||
request.post({
|
request.post({
|
||||||
url: 'http://localhost:8378/1/schemas/NewClass',
|
url: 'http://localhost:8378/1/schemas/NewClass',
|
||||||
|
|||||||
@@ -530,6 +530,8 @@ export default class SchemaController {
|
|||||||
delete existingFields._rperm;
|
delete existingFields._rperm;
|
||||||
delete existingFields._wperm;
|
delete existingFields._wperm;
|
||||||
const newSchema = buildMergedSchemaObject(existingFields, submittedFields);
|
const newSchema = buildMergedSchemaObject(existingFields, submittedFields);
|
||||||
|
const defaultFields = defaultColumns[className] || defaultColumns._Default;
|
||||||
|
const fullNewSchema = Object.assign({}, newSchema, defaultFields);
|
||||||
const validationError = this.validateSchemaData(className, newSchema, classLevelPermissions, Object.keys(existingFields));
|
const validationError = this.validateSchemaData(className, newSchema, classLevelPermissions, Object.keys(existingFields));
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
throw new Parse.Error(validationError.code, validationError.error);
|
throw new Parse.Error(validationError.code, validationError.error);
|
||||||
@@ -561,7 +563,7 @@ export default class SchemaController {
|
|||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
})
|
})
|
||||||
.then(() => this.setPermissions(className, classLevelPermissions, newSchema))
|
.then(() => this.setPermissions(className, classLevelPermissions, newSchema))
|
||||||
.then(() => this._dbAdapter.setIndexesWithSchemaFormat(className, indexes, schema.indexes, newSchema))
|
.then(() => this._dbAdapter.setIndexesWithSchemaFormat(className, indexes, schema.indexes, fullNewSchema))
|
||||||
.then(() => this.reloadData({ clearCache: true }))
|
.then(() => this.reloadData({ clearCache: true }))
|
||||||
//TODO: Move this logic into the database adapter
|
//TODO: Move this logic into the database adapter
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user