Skip to content

Update PostgresStorageAdapter.js #3578

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

Merged
merged 7 commits into from
Mar 4, 2017
Merged
Changes from all commits
Commits
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
48 changes: 21 additions & 27 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,41 +1160,35 @@ export class PostgresStorageAdapter {
}

performInitialization({ VolatileClassesSchemas }) {
const now = new Date().getTime();
debug('performInitialization');
let promises = VolatileClassesSchemas.map((schema) => {
return this.createTable(schema.className, schema).catch((err) =>{
const promises = VolatileClassesSchemas.map((schema) => {
return this.createTable(schema.className, schema).catch((err) => {
if (err.code === PostgresDuplicateRelationError || err.code === Parse.Error.INVALID_CLASS_NAME) {
return Promise.resolve();
}
throw err;
});
});
/* eslint-disable no-console */
promises = promises.concat([
this._client.none(sql.misc.jsonObjectSetKeys).catch((err) => {
console.error(err);
}),
this._client.none(sql.array.add).catch((err) => {
console.error(err);
}),
this._client.none(sql.array.addUnique).catch((err) => {
console.error(err);
}),
this._client.none(sql.array.remove).catch((err) => {
console.error(err);
}),
this._client.none(sql.array.containsAll).catch((err) => {
console.error(err);
}),
this._client.none(sql.array.contains).catch((err) => {
console.error(err);
return Promise.all(promises)
.then(() => {
return this._client.tx(t => {
return t.batch([
t.none(sql.misc.jsonObjectSetKeys),
t.none(sql.array.add),
t.none(sql.array.addUnique),
t.none(sql.array.remove),
t.none(sql.array.containsAll),
t.none(sql.array.contains)
]);
});
})
.then(data => {
debug(`initializationDone in ${data.duration}`);
})
]);
/* eslint-enable no-console */
return Promise.all(promises).then(() => {
debug(`initialzationDone in ${new Date().getTime() - now}`);
}, () => {});
.catch(error => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm. so if you catch the error and then do nothing with it is that the right thing? will parse server fail? should it?

i'm assuming you're using console instead of logger cause we can't know that the logger is available yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end result after the change should be identical to what it was, except the integrity is ensured + using just one connection.

/* eslint-disable no-console */
console.error(error);
});
}
}

Expand Down