Skip to content
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

Postgres adapter #2012

Merged
merged 44 commits into from
Jun 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2abccbb
index on unique-indexes: c454180 Revert "Log objects rather than JSON…
drew-gross Jun 6, 2016
7a4fa7b
Start dealing with test shittyness
drew-gross Jun 7, 2016
2243f04
Make specific server config for tests async
drew-gross Jun 7, 2016
b0d7077
Fix email validation
drew-gross Jun 7, 2016
0ad3b11
Fix broken cloud code
drew-gross Jun 8, 2016
88d7318
Save callback to variable
drew-gross Jun 8, 2016
5c86841
undo
drew-gross Jun 8, 2016
84b4785
Remove adaptiveCollection
drew-gross Jun 2, 2016
f617b9a
Remove an adaptiveCollection use
drew-gross Jun 2, 2016
1f685bc
Remove an adaptiveCollection
drew-gross Jun 2, 2016
48145ab
make adaptiveCollection private
drew-gross Jun 2, 2016
aa50363
Remove collection from mongoadapter
drew-gross Jun 2, 2016
1cb89d3
Move schema collection usage into mongo adapter
drew-gross Jun 2, 2016
177b68a
stop relying on mongo format for removing join tables
drew-gross Jun 2, 2016
4297a8d
reduce usage of schemaCollection
drew-gross Jun 2, 2016
f1fa13d
remove uses of _collection
drew-gross Jun 2, 2016
5528928
Move CLP setting into mongo adapter
drew-gross Jun 2, 2016
990b08e
remove all uses of schemaCollection
drew-gross Jun 2, 2016
74eb5c0
make schemaCollection private
drew-gross Jun 2, 2016
c5e7493
remove transform from schemaCollection
drew-gross Jun 2, 2016
92604c2
rename some stuff
drew-gross Jun 3, 2016
f03bb3e
Tweak paramaters and stuff
drew-gross Jun 3, 2016
019cf07
reorder some params
drew-gross Jun 3, 2016
f2e16ee
reorder find() arguments
drew-gross Jun 3, 2016
1a551d0
finishsh touching up argument order
drew-gross Jun 3, 2016
71944b9
Accept a database adapter as a parameter
drew-gross Jun 3, 2016
a3a9678
First passing test with postgres!
drew-gross Jun 4, 2016
523dd92
Actually use the provided className
drew-gross Jun 6, 2016
2794aea
Fix tests
drew-gross Jun 8, 2016
1adc5d5
Setup travis
drew-gross Jun 9, 2016
57b2b42
fix travis maybe
drew-gross Jun 9, 2016
d781687
try removing db user
drew-gross Jun 9, 2016
054f5be
indentation?
drew-gross Jun 9, 2016
b78de36
remove postgres version setting
drew-gross Jun 9, 2016
bd5bf21
sudo maybe?
drew-gross Jun 9, 2016
88945a4
use postgres username
drew-gross Jun 9, 2016
f2b1642
fix check for _PushStatus
drew-gross Jun 9, 2016
ecb5ac7
excludes
drew-gross Jun 9, 2016
8df3989
remove db=mongo
drew-gross Jun 9, 2016
41f7352
allow postgres to fail
drew-gross Jun 9, 2016
96c09e6
Fix allow failure
drew-gross Jun 9, 2016
19b3720
postgres 9.4
drew-gross Jun 9, 2016
2e9127b
Remove mongo implementations and fix test
drew-gross Jun 11, 2016
ba6f828
Fix test leaving behind connections
drew-gross Jun 12, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ language: node_js
node_js:
- '4.3'
- '6.1'
services:
- postgresql
addons:
postgresql: '9.4'
before_script:
- psql -c 'create database parse_server_postgres_adapter_test_database;' -U postgres
env:
global:
- COVERAGE_OPTION='./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**'
matrix:
- PARSE_SERVER_TEST_DB=postgres
- MONGODB_VERSION=2.6.11
- MONGODB_VERSION=3.0.8
- MONGODB_VERSION=3.2.6
matrix:
fast_finish: true,
allow_failures:
- env: PARSE_SERVER_TEST_DB=postgres
branches:
only:
- master
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"parse-server-push-adapter": "^1.0.0",
"parse-server-s3-adapter": "^1.0.1",
"parse-server-simple-mailgun-adapter": "^1.0.0",
"pg-promise": "^4.4.0",
"redis": "^2.5.0-1",
"request": "^2.65.0",
"request-promise": "^3.0.0",
Expand Down
16 changes: 8 additions & 8 deletions spec/MongoStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const databaseURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDataba
describe('MongoStorageAdapter', () => {
beforeEach(done => {
new MongoStorageAdapter({ uri: databaseURI })
.deleteAllSchemas()
.deleteAllClasses()
.then(done, fail);
});

Expand Down Expand Up @@ -49,7 +49,7 @@ describe('MongoStorageAdapter', () => {

it('stores objectId in _id', done => {
let adapter = new MongoStorageAdapter({ uri: databaseURI });
adapter.createObject('Foo', { objectId: 'abcde' }, { fields: { objectId: 'String' } })
adapter.createObject('Foo', {}, { objectId: 'abcde' })
.then(() => adapter._rawFind('Foo', {}))
.then(results => {
expect(results.length).toEqual(1);
Expand All @@ -70,10 +70,10 @@ describe('MongoStorageAdapter', () => {
}
};
let adapter = new MongoStorageAdapter({ uri: databaseURI });
adapter.createObject('APointerDarkly', obj, { fields: {
adapter.createObject('APointerDarkly', { fields: {
objectId: { type: 'String' },
aPointer: { type: 'Pointer', targetClass: 'JustThePointer' },
}})
}}, obj)
.then(() => adapter._rawFind('APointerDarkly', {}))
.then(results => {
expect(results.length).toEqual(1);
Expand All @@ -90,7 +90,7 @@ describe('MongoStorageAdapter', () => {
let adapter = new MongoStorageAdapter({ uri: databaseURI });
let schema = { fields : { subdoc: { type: 'Object' } } };
let obj = { subdoc: {foo: 'bar', wu: 'tan'} };
adapter.createObject('MyClass', obj, schema)
adapter.createObject('MyClass', schema, obj)
.then(() => adapter._rawFind('MyClass', {}))
.then(results => {
expect(results.length).toEqual(1);
Expand All @@ -99,7 +99,7 @@ describe('MongoStorageAdapter', () => {
expect(mob.subdoc.foo).toBe('bar');
expect(mob.subdoc.wu).toBe('tan');
let obj = { 'subdoc.wu': 'clan' };
return adapter.findOneAndUpdate('MyClass', {}, schema, obj);
return adapter.findOneAndUpdate('MyClass', schema, {}, obj);
})
.then(() => adapter._rawFind('MyClass', {}))
.then(results => {
Expand Down Expand Up @@ -127,15 +127,15 @@ describe('MongoStorageAdapter', () => {
object: { type: 'Object' },
date: { type: 'Date' },
} };
adapter.createObject('MyClass', obj, schema)
adapter.createObject('MyClass', schema, obj)
.then(() => adapter._rawFind('MyClass', {}))
.then(results => {
expect(results.length).toEqual(1);
let mob = results[0];
expect(mob.array instanceof Array).toBe(true);
expect(typeof mob.object).toBe('object');
expect(mob.date instanceof Date).toBe(true);
return adapter.find('MyClass', {}, schema, {});
return adapter.find('MyClass', schema, {}, {});
})
.then(results => {
expect(results.length).toEqual(1);
Expand Down
4 changes: 2 additions & 2 deletions spec/OAuth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ describe('OAuth', function() {
"Expiration should be cleared");
// make sure the auth data is properly deleted
var config = new Config(Parse.applicationId);
config.database.adapter.find('_User', { objectId: model.id }, {
config.database.adapter.find('_User', {
fields: Object.assign({}, defaultColumns._Default, defaultColumns._Installation),
}, {})
}, { objectId: model.id }, {})
.then(res => {
expect(res.length).toBe(1);
expect(res[0]._auth_data_myoauth).toBeUndefined();
Expand Down
118 changes: 51 additions & 67 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ describe('miscellaneous', function() {
expect(typeof obj.id).toBe('string');
expect(typeof obj.createdAt.toGMTString()).toBe('string');
done();
}, function(err) { console.log(err); });
}, error => {
fail(JSON.stringify(error));
done();
});
});

it('get a TestObject', function(done) {
Expand Down Expand Up @@ -122,81 +125,63 @@ describe('miscellaneous', function() {
});

it('ensure that if people already have duplicate users, they can still sign up new users', done => {
reconfigureServer({})
let config = new Config('test');
// Remove existing data to clear out unique index
.then(TestUtils.destroyAllDataPermanently)
TestUtils.destroyAllDataPermanently()
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'x', username: 'u' }))
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'y', username: 'u' }))
// Create a new server to try to recreate the unique indexes
.then(reconfigureServer)
.catch(() => {
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('zxcv');
// Sign up with new email still works
return user.signUp().catch(fail);
})
.then(() => {
let adapter = new MongoStorageAdapter({
uri: 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase',
collectionPrefix: 'test_',
});
adapter.createObject('_User', { objectId: 'x', username: 'u' }, requiredUserFields)
.then(() => adapter.createObject('_User', { objectId: 'y', username: 'u' }, requiredUserFields))
.then(() => {
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('zxcv');
return user.signUp();
})
.then(() => {
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('u');
user.signUp()
.catch(error => {
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
done();
});
})
.catch(error => {
fail(JSON.stringify(error));
done();
});
}, () => {
fail('destroyAllDataPermanently failed')
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('u');
// sign up with duplicate username doens't
return user.signUp()
})
.catch(error => {
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
done();
});
})
});

it('ensure that if people already have duplicate emails, they can still sign up new users', done => {
reconfigureServer({})
// Wipe out existing database with unique index so we can create a duplicate user
.then(TestUtils.destroyAllDataPermanently)
let config = new Config('test');
// Remove existing data to clear out unique index
TestUtils.destroyAllDataPermanently()
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'x', email: 'a@b.c' }))
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'y', email: 'a@b.c' }))
.then(reconfigureServer)
.catch(() => {
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('qqq');
user.setEmail('unique@unique.unique');
return user.signUp().catch(fail);
})
.then(() => {
let adapter = new MongoStorageAdapter({
uri: 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase',
collectionPrefix: 'test_',
});
adapter.createObject('_User', { objectId: 'x', email: 'a@b.c' }, requiredUserFields)
.then(() => adapter.createObject('_User', { objectId: 'y', email: 'a@b.c' }, requiredUserFields))
.then(() => {
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('qqq');
user.setEmail('unique@unique.unique');
return user.signUp();
})
.then(() => {
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('www');
user.setEmail('a@b.c');
user.signUp()
.catch(error => {
expect(error.code).toEqual(Parse.Error.EMAIL_TAKEN);
done();
});
})
.catch(error => {
fail(JSON.stringify(error));
done();
});
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('www');
user.setEmail('a@b.c');
return user.signUp()
})
.catch(error => {
expect(error.code).toEqual(Parse.Error.EMAIL_TAKEN);
done();
});
});

it('ensure that if you try to sign up a user with a unique username and email, but duplicates in some other field that has a uniqueness constraint, you get a regular duplicate value error', done => {
let config = new Config('test');
config.database.adapter.ensureUniqueness('_User', ['randomField'], requiredUserFields)
config.database.adapter.ensureUniqueness('_User', requiredUserFields, ['randomField'])
.then(() => {
let user = new Parse.User();
user.setPassword('asdf');
Expand Down Expand Up @@ -228,8 +213,7 @@ describe('miscellaneous', function() {
expect(typeof user.id).toEqual('string');
expect(user.get('password')).toBeUndefined();
expect(user.getSessionToken()).not.toBeUndefined();
Parse.User.logOut();
done();
Parse.User.logOut().then(done);
}, error: function(error) {
fail(error);
}
Expand Down Expand Up @@ -366,7 +350,7 @@ describe('miscellaneous', function() {
return obj.save();
}).then(() => {
let config = new Config(appId);
return config.database.adapter.find('TestObject', {}, { fields: {} }, {});
return config.database.adapter.find('TestObject', { fields: {} }, {}, {});
}).then((results) => {
expect(results.length).toEqual(1);
expect(results[0]['foo']).toEqual('bar');
Expand Down
42 changes: 23 additions & 19 deletions spec/ParseGlobalConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ let Config = require('../src/Config');
describe('a GlobalConfig', () => {
beforeEach(done => {
let config = new Config('test');
config.database.adapter.adaptiveCollection('_GlobalConfig')
.then(coll => coll.upsertOne({ '_id': 1 }, { $set: { params: { companies: ['US', 'DK'] } } }))
.then(() => { done(); });
config.database.adapter.upsertOneObject(
'_GlobalConfig',
{ fields: {} },
{ objectId: 1 },
{ params: { companies: ['US', 'DK'] } }
).then(done);
});

it('can be retrieved', (done) => {
Expand Down Expand Up @@ -90,22 +93,23 @@ describe('a GlobalConfig', () => {

it('failed getting config when it is missing', (done) => {
let config = new Config('test');
config.database.adapter.adaptiveCollection('_GlobalConfig')
.then(coll => coll.deleteOne({ '_id': 1 }))
.then(() => {
request.get({
url : 'http://localhost:8378/1/config',
json : true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key' : 'test'
}
}, (error, response, body) => {
expect(response.statusCode).toEqual(200);
expect(body.params).toEqual({});
done();
});
config.database.adapter.deleteObjectsByQuery(
'_GlobalConfig',
{ fields: { params: { __type: 'String' } } },
{ objectId: 1 }
).then(() => {
request.get({
url : 'http://localhost:8378/1/config',
json : true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key' : 'test'
}
}, (error, response, body) => {
expect(response.statusCode).toEqual(200);
expect(body.params).toEqual({});
done();
});
});
});

});
2 changes: 1 addition & 1 deletion spec/ParseHooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Parse.Hooks = require("../src/cloud-code/Parse.Hooks");

var port = 12345;
var hookServerURL = "http://localhost:"+port;
let AppCache = require('../src/cache').AppCache;

var app = express();
app.use(bodyParser.json({ 'type': '*/*' }))
app.listen(12345);
let AppCache = require('../src/cache').AppCache;

describe('Hooks', () => {

Expand Down
Loading