Skip to content

PG: Index Support and Improvements #4629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
49 changes: 44 additions & 5 deletions spec/ParsePolygon.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const TestObject = Parse.Object.extend('TestObject');
const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageAdapter').default;
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
const Config = require('../src/Config');
const rp = require('request-promise');

const masterKeyHeaders = {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
};

const defaultHeaders = {
'X-Parse-Application-Id': 'test',
'X-Parse-Rest-API-Key': 'rest'
Expand Down Expand Up @@ -272,6 +279,39 @@ describe('Parse.Polygon testing', () => {
});
});

describe_only_db('postgres')('schemas', () => {
it('can create polygon index', (done) => {
const adapter = Config.get('test').database.adapter;
const coords = [[0,0],[0,1],[1,1],[1,0],[0,0]];
const polygon = new Parse.Polygon(coords);
const obj = new TestObject();
obj.set('polygon', polygon);
reconfigureServer({
appId: 'test',
restAPIKey: 'test',
publicServerURL: 'http://localhost:8378/1',
}).then(() => {
return obj.save();
}).then(() => {
return adapter.getIndexes('TestObject');
}).then((indexes) => {
rp.get({
url: 'http://localhost:8378/1/schemas/TestObject',
headers: masterKeyHeaders,
json: true,
}, (error, response, body) => {
expect(body.indexes).toEqual(indexes);
expect(indexes._id_._id).toEqual(1);
expect(indexes.polygon_2dsphere.polygon).toEqual(1);
done();
});
}).catch(error => {
console.log(error);
done();
});
});
});

describe_only_db('mongo')('Parse.Polygon testing', () => {

beforeEach(() => require('../lib/TestUtils').destroyAllDataPermanently());
Expand Down Expand Up @@ -313,11 +353,10 @@ describe_only_db('mongo')('Parse.Polygon testing', () => {
equal(resp.polygon2, polygon);
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
equal(indexes.length, 4);
equal(indexes[0].key, {_id: 1});
equal(indexes[1].key, {location: '2d'});
equal(indexes[2].key, {polygon: '2dsphere'});
equal(indexes[3].key, {polygon2: '2dsphere'});
equal(indexes._id_, {_id: 1});
equal(indexes.location_2d, {location: '2d'});
equal(indexes.polygon_2dsphere, {polygon: '2dsphere'});
equal(indexes.polygon2_2dsphere, {polygon2: '2dsphere'});
done();
}, done.fail);
});
Expand Down
22 changes: 10 additions & 12 deletions spec/ParseQuery.FullTextSearch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,13 @@ describe_only_db('mongo')('[mongodb] Parse.Query Full Text Search testing', () =
}).then(() => {
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(1);
expect(indexes._id_).toBeDefined();
return databaseAdapter.createIndex('TestObject', {subject: 'text', comment: 'text'});
}).then(() => {
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(2);
expect(indexes._id_).toBeDefined();
expect(indexes.subject_text_comment_text).toBeDefined();
const where = {
subject: {
$text: {
Expand All @@ -314,7 +315,8 @@ describe_only_db('mongo')('[mongodb] Parse.Query Full Text Search testing', () =
expect(resp.results.length).toEqual(3);
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(2);
expect(indexes._id_).toBeDefined();
expect(indexes.subject_text_comment_text).toBeDefined();
rp.get({
url: 'http://localhost:8378/1/schemas/TestObject',
headers: {
Expand All @@ -324,10 +326,7 @@ describe_only_db('mongo')('[mongodb] Parse.Query Full Text Search testing', () =
json: true,
}, (error, response, body) => {
expect(body.indexes._id_).toBeDefined();
expect(body.indexes._id_._id).toEqual(1);
expect(body.indexes.subject_text_comment_text).toBeDefined();
expect(body.indexes.subject_text_comment_text.subject).toEqual('text');
expect(body.indexes.subject_text_comment_text.comment).toEqual('text');
done();
});
}).catch(done.fail);
Expand All @@ -339,7 +338,7 @@ describe_only_db('mongo')('[mongodb] Parse.Query Full Text Search testing', () =
}).then(() => {
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(1);
expect(indexes._id_).toBeDefined();
return rp.put({
url: 'http://localhost:8378/1/schemas/TestObject',
json: true,
Expand All @@ -357,7 +356,8 @@ describe_only_db('mongo')('[mongodb] Parse.Query Full Text Search testing', () =
}).then(() => {
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(2);
expect(indexes._id_).toBeDefined();
expect(indexes.text_test).toBeDefined();
const where = {
subject: {
$text: {
Expand All @@ -379,7 +379,8 @@ describe_only_db('mongo')('[mongodb] Parse.Query Full Text Search testing', () =
expect(resp.results.length).toEqual(3);
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(2);
expect(indexes._id_).toBeDefined();
expect(indexes.text_test).toBeDefined();
rp.get({
url: 'http://localhost:8378/1/schemas/TestObject',
headers: {
Expand All @@ -389,10 +390,7 @@ describe_only_db('mongo')('[mongodb] Parse.Query Full Text Search testing', () =
json: true,
}, (error, response, body) => {
expect(body.indexes._id_).toBeDefined();
expect(body.indexes._id_._id).toEqual(1);
expect(body.indexes.text_test).toBeDefined();
expect(body.indexes.text_test.subject).toEqual('text');
expect(body.indexes.text_test.comment).toEqual('text');
done();
});
}).catch(done.fail);
Expand Down
40 changes: 39 additions & 1 deletion spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ describe('SchemaController', () => {
});
});

it('creates non-custom classes which include relation field', done => {
it_only_db('mongo')('creates non-custom classes which include relation field', done => {
config.database.loadSchema()
//as `_Role` is always created by default, we only get it here
.then(schema => schema.getOneSchema('_Role'))
Expand All @@ -630,6 +630,44 @@ describe('SchemaController', () => {
delete: { '*': true },
addField: { '*': true },
},
indexes: {
_id_: { _id: 1 },
name_1: { name: 1 },
},
};
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
done();
});
});

it_only_db('postgres')('creates non-custom classes which include relation field', done => {
config.database.loadSchema()
//as `_Role` is always created by default, we only get it here
.then(schema => schema.getOneSchema('_Role'))
.then(actualSchema => {
const expectedSchema = {
className: '_Role',
fields: {
objectId: { type: 'String' },
updatedAt: { type: 'Date' },
createdAt: { type: 'Date' },
ACL: { type: 'ACL' },
name: { type: 'String' },
users: { type: 'Relation', targetClass: '_User' },
roles: { type: 'Relation', targetClass: '_Role' },
},
classLevelPermissions: {
find: { '*': true },
get: { '*': true },
create: { '*': true },
update: { '*': true },
delete: { '*': true },
addField: { '*': true },
},
indexes: {
_id_: { _id: 1 },
unique_name: { name: 1 },
},
};
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
done();
Expand Down
Loading