index on unique-indexes: c454180 Revert "Log objects rather than JSON stringified objects (#1922)"

reconfigure username/email tests

Fix broken cloud code

Save callback to variable

undo

Fix all tests where connections are left open after server closes.

Fix issues caused by missing gridstore adapter

remove uses of _collection

reorder find() arguments

Accept a database adapter as a parameter

sudo maybe?

use postgres username

reorder find() arguments

Build objects with default fields correctly

Don't tell adapter about ACL

WIP
This commit is contained in:
Drew Gross
2016-06-06 13:47:11 -07:00
parent 693707b33c
commit f75c8b3a4d
7 changed files with 68 additions and 27 deletions

View File

@@ -220,6 +220,18 @@ const fieldTypeIsInvalid = ({ type, targetClass }) => {
return undefined;
}
const convertSchemaToAdapterSchema = schema => {
schema = injectDefaultSchema(schema);
delete schema.fields.ACL;
if (schema.className === '_User') {
delete schema.fields.password;
schema.fields._hashed_password = { type: 'String' };
}
return schema;
}
const injectDefaultSchema = schema => ({
className: schema.className,
fields: {
@@ -293,7 +305,7 @@ class SchemaController {
return Promise.reject(validationError);
}
return this._dbAdapter.createClass(className, { fields, classLevelPermissions })
return this._dbAdapter.createClass(className, convertSchemaToAdapterSchema({ fields, classLevelPermissions, className }))
.catch(error => {
if (error && error.code === Parse.Error.DUPLICATE_VALUE) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} already exists.`);
@@ -360,20 +372,15 @@ class SchemaController {
// Returns a promise that resolves successfully to the new schema
// object or fails with a reason.
// If 'freeze' is true, refuse to modify the schema.
enforceClassExists(className, freeze) {
enforceClassExists(className) {
if (this.data[className]) {
return Promise.resolve(this);
}
if (freeze) {
throw new Parse.Error(Parse.Error.INVALID_JSON,
'schema is frozen, cannot add: ' + className);
}
// We don't have this class. Update the schema
return this.addClassIfNotExists(className, {}).then(() => {
return this.addClassIfNotExists(className).then(() => {
// The schema update succeeded. Reload the schema
return this.reloadData();
}, () => {
}, error => {
// The schema update failed. This can be okay - it might
// have failed because there's a race condition and a different
// client is making the exact same schema update that we want.
@@ -381,8 +388,12 @@ class SchemaController {
return this.reloadData();
}).then(() => {
// Ensure that the schema now validates
return this.enforceClassExists(className, true);
}, () => {
if (this.data[className]) {
return this;
} else {
throw new Parse.Error(Parse.Error.INVALID_JSON, `Failed to add ${className}`);
}
}, error => {
// The schema still doesn't validate. Give up
throw new Parse.Error(Parse.Error.INVALID_JSON, 'schema class name does not revalidate');
});