PG: Support multiple global config (#5242)
* PG: Support Multiple Configs * rename test * refactor
This commit is contained in:
@@ -4517,4 +4517,53 @@ describe('Parse.Query testing', () => {
|
|||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(() => done());
|
.catch(() => done());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can add new config to existing config', async () => {
|
||||||
|
await request({
|
||||||
|
method: 'PUT',
|
||||||
|
url: 'http://localhost:8378/1/config',
|
||||||
|
json: true,
|
||||||
|
body: {
|
||||||
|
params: {
|
||||||
|
files: [{ __type: 'File', name: 'name', url: 'http://url' }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
});
|
||||||
|
|
||||||
|
await request({
|
||||||
|
method: 'PUT',
|
||||||
|
url: 'http://localhost:8378/1/config',
|
||||||
|
json: true,
|
||||||
|
body: {
|
||||||
|
params: { newConfig: 'good' },
|
||||||
|
},
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await Parse.Config.get();
|
||||||
|
equal(result.get('files')[0].toJSON(), {
|
||||||
|
__type: 'File',
|
||||||
|
name: 'name',
|
||||||
|
url: 'http://url',
|
||||||
|
});
|
||||||
|
equal(result.get('newConfig'), 'good');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can set object type key', async () => {
|
||||||
|
const data = { bar: true, baz: 100 };
|
||||||
|
const object = new TestObject();
|
||||||
|
object.set('objectField', data);
|
||||||
|
await object.save();
|
||||||
|
|
||||||
|
const query = new Parse.Query(TestObject);
|
||||||
|
let result = await query.get(object.id);
|
||||||
|
equal(result.get('objectField'), data);
|
||||||
|
|
||||||
|
object.set('objectField.baz', 50, { ignoreValidation: true });
|
||||||
|
await object.save();
|
||||||
|
|
||||||
|
result = await query.get(object.id);
|
||||||
|
equal(result.get('objectField'), { bar: true, baz: 50 });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -969,6 +969,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
|||||||
const qs = `CREATE TABLE IF NOT EXISTS $1:name (${patternsArray.join()})`;
|
const qs = `CREATE TABLE IF NOT EXISTS $1:name (${patternsArray.join()})`;
|
||||||
const values = [className, ...valuesArray];
|
const values = [className, ...valuesArray];
|
||||||
|
|
||||||
|
debug(qs, values);
|
||||||
return conn.task('create-table', function*(t) {
|
return conn.task('create-table', function*(t) {
|
||||||
try {
|
try {
|
||||||
yield self._ensureSchemaCollectionExists(t);
|
yield self._ensureSchemaCollectionExists(t);
|
||||||
@@ -1426,6 +1427,18 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
|||||||
schema = toPostgresSchema(schema);
|
schema = toPostgresSchema(schema);
|
||||||
|
|
||||||
const originalUpdate = { ...update };
|
const originalUpdate = { ...update };
|
||||||
|
|
||||||
|
// Set flag for dot notation fields
|
||||||
|
const dotNotationOptions = {};
|
||||||
|
Object.keys(update).forEach(fieldName => {
|
||||||
|
if (fieldName.indexOf('.') > -1) {
|
||||||
|
const components = fieldName.split('.');
|
||||||
|
const first = components.shift();
|
||||||
|
dotNotationOptions[first] = true;
|
||||||
|
} else {
|
||||||
|
dotNotationOptions[fieldName] = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
update = handleDotFields(update);
|
update = handleDotFields(update);
|
||||||
// Resolve authData first,
|
// Resolve authData first,
|
||||||
// So we don't end up with multiple key updates
|
// So we don't end up with multiple key updates
|
||||||
@@ -1615,13 +1628,18 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
|||||||
},
|
},
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
// Override Object
|
||||||
|
let updateObject = "'{}'::jsonb";
|
||||||
|
|
||||||
|
if (dotNotationOptions[fieldName]) {
|
||||||
|
// Merge Object
|
||||||
|
updateObject = `COALESCE($${index}:name, '{}'::jsonb)`;
|
||||||
|
}
|
||||||
updatePatterns.push(
|
updatePatterns.push(
|
||||||
`$${index}:name = ('{}'::jsonb ${deletePatterns} ${incrementPatterns} || $${index +
|
`$${index}:name = (${updateObject} ${deletePatterns} ${incrementPatterns} || $${index +
|
||||||
1 +
|
1 +
|
||||||
keysToDelete.length}::jsonb )`
|
keysToDelete.length}::jsonb )`
|
||||||
);
|
);
|
||||||
|
|
||||||
values.push(fieldName, ...keysToDelete, JSON.stringify(fieldValue));
|
values.push(fieldName, ...keysToDelete, JSON.stringify(fieldValue));
|
||||||
index += 2 + keysToDelete.length;
|
index += 2 + keysToDelete.length;
|
||||||
} else if (
|
} else if (
|
||||||
|
|||||||
Reference in New Issue
Block a user