-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix(#193): only create indexes if table does not exist #194
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet. One minor change + unit test request.
couch2pg/src/setup.js
Outdated
// note that `CREATE INDEX IF NOT EXISTS` acquires a lock | ||
// even if the index exists, so cannot rely on it here, | ||
// have to actually check if the table exists in a separate query | ||
const tableExists = await checkTableExists(client); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can return early here instead:
const tableExists = await checkTableExists(client); | |
if (await checkTableExists(client)) { | |
return; | |
} |
couch2pg/tests/unit/setup.spec.js
Outdated
@@ -13,6 +13,10 @@ describe('setup', () => { | |||
end: sinon.stub(), | |||
}; | |||
|
|||
pgClient.query.withArgs(`SELECT 1 FROM v1.whatever LIMIT 1;`).rejects({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a unit test where the table already exists and doesn't get created on startup.
couch2pg/src/setup.js
Outdated
return true; | ||
} catch (error) { | ||
// "Undefined table" error code in PostgreSQL | ||
if (error.code === '42P01') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have a library of PG errors somewhere instead of scattered magic strings all over. Do we have other PG errors that we work around in this codebase?
looking a bit deeper into postgres locking and there's a simpler way to fix this; using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spending extra time to read about how locks get triggered in PG! This is absolutely much better!
🎉 This PR is included in version 1.3.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
closes #193
check if table exists in a separate query before creating indexes