Postgres adapter (#2012)
* Remove adaptiveCollection * Remove an adaptiveCollection use * Remove an adaptiveCollection * make adaptiveCollection private * Remove collection from mongoadapter * Move schema collection usage into mongo adapter * stop relying on mongo format for removing join tables * reduce usage of schemaCollection * remove uses of _collection * Move CLP setting into mongo adapter * remove all uses of schemaCollection * make schemaCollection private * remove transform from schemaCollection * rename some stuff * Tweak paramaters and stuff * reorder some params * reorder find() arguments * finishsh touching up argument order * Accept a database adapter as a parameter * First passing test with postgres! * Actually use the provided className * index on unique-indexes: c454180 Revert "Log objects rather than JSON stringified objects (#1922)" * Start dealing with test shittyness * Make specific server config for tests async * Fix email validation * Fix broken cloud code * Save callback to variable * undo * Fix tests * Setup travis * fix travis maybe * try removing db user * indentation? * remove postgres version setting * sudo maybe? * use postgres username * fix check for _PushStatus * excludes * remove db=mongo * allow postgres to fail * Fix allow failure * postgres 9.4 * Remove mongo implementations and fix test * Fix test leaving behind connections
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
|
||||
import MongoCollection from './MongoCollection';
|
||||
import * as transform from './MongoTransform';
|
||||
|
||||
function mongoFieldToParseSchemaField(type) {
|
||||
if (type[0] === '*') {
|
||||
@@ -154,20 +153,12 @@ class MongoSchemaCollection {
|
||||
}
|
||||
|
||||
// Atomically find and delete an object based on query.
|
||||
// The result is the promise with an object that was in the database before deleting.
|
||||
// Postgres Note: Translates directly to `DELETE * FROM ... RETURNING *`, which will return data after delete is done.
|
||||
findAndDeleteSchema(name: string) {
|
||||
// arguments: query, sort
|
||||
return this._collection._mongoCollection.findAndRemove(_mongoSchemaQueryFromNameQuery(name), []).then(document => {
|
||||
// Value is the object where mongo returns multiple fields.
|
||||
return document.value;
|
||||
});
|
||||
return this._collection._mongoCollection.findAndRemove(_mongoSchemaQueryFromNameQuery(name), []);
|
||||
}
|
||||
|
||||
// Add a collection. Currently the input is in mongo format, but that will change to Parse format in a
|
||||
// later PR. Returns a promise that is expected to resolve with the newly created schema, in Parse format.
|
||||
// If the class already exists, returns a promise that rejects with undefined as the reason. If the collection
|
||||
// can't be added for a reason other than it already existing, requirements for rejection reason are TBD.
|
||||
// Returns a promise that is expected to resolve with the newly created schema, in Parse format.
|
||||
// If the class already exists, returns a promise that rejects with DUPLICATE_VALUE as the reason.
|
||||
addSchema(name: string, fields, classLevelPermissions) {
|
||||
let mongoSchema = mongoSchemaFromFieldsAndClassNameAndCLP(fields, name, classLevelPermissions);
|
||||
let mongoObject = _mongoSchemaObjectFromNameFields(name, mongoSchema);
|
||||
@@ -175,9 +166,10 @@ class MongoSchemaCollection {
|
||||
.then(result => mongoSchemaToParseSchema(result.ops[0]))
|
||||
.catch(error => {
|
||||
if (error.code === 11000) { //Mongo's duplicate key error
|
||||
throw undefined;
|
||||
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, 'Class already exists.');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -192,8 +184,8 @@ class MongoSchemaCollection {
|
||||
// Add a field to the schema. If database does not support the field
|
||||
// type (e.g. mongo doesn't support more than one GeoPoint in a class) reject with an "Incorrect Type"
|
||||
// Parse error with a desciptive message. If the field already exists, this function must
|
||||
// not modify the schema, and must reject with an error. Exact error format is TBD. If this function
|
||||
// is called for a class that doesn't exist, this function must create that class.
|
||||
// not modify the schema, and must reject with DUPLICATE_VALUE error.
|
||||
// If this is called for a class that doesn't exist, this function must create that class.
|
||||
|
||||
// TODO: throw an error if an unsupported field type is passed. Deciding whether a type is supported
|
||||
// should be the job of the adapter. Some adapters may not support GeoPoint at all. Others may
|
||||
@@ -229,10 +221,6 @@ class MongoSchemaCollection {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
get transform() {
|
||||
return transform;
|
||||
}
|
||||
}
|
||||
|
||||
// Exported for testing reasons and because we haven't moved all mongo schema format
|
||||
|
||||
Reference in New Issue
Block a user