-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Postgres: Add a check to determine if table already exists to elide CREATE query #526
Postgres: Add a check to determine if table already exists to elide CREATE query #526
Conversation
c8e03d2
to
5864780
Compare
8e5aca6
to
9d00b4b
Compare
Pull Request Test Coverage Report for Build 247
💛 - Coveralls |
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 the PR and tests!!
database/postgres/postgres_test.go
Outdated
|
||
// create user who is not the owner. Although we're concatenating strings in an sql statement it should be fine | ||
// since this is a test environment and we're not expecting to the pgPassword to be malicious | ||
if err := d.Run(strings.NewReader("CREATE USER not_owner WITH ENCRYPTED PASSWORD '" + pgPassword + "'")); err != nil { |
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.
Looks like there are a bunch of setup statements for these tests. Create a mustRun(testing.T*, []string)
method and use that.
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.
Awesome! That makes this a lot cleaner
|
||
var e *database.Error | ||
if !errors.As(err, &e) || err == nil { | ||
t.Fatal("Unexpected error, want permission denied error. Got: ", err) |
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.
Is the permission denied error exposed? e.g. a postgres error code
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.
Yup, but we have to parse the error string to do it. Made the change!
7ea2991
to
9788837
Compare
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 addressing my feedback. The test setup code looks much cleaner now!
Also, thanks for also updating the pgx driver!
database/pgx/pgx_test.go
Outdated
t.Fatal("Unexpected error, want permission denied error. Got: ", err) | ||
} | ||
|
||
if strings.Contains(e.Err, "permission denied for schema barfoo") { |
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.
Shouldn't this be !strings.Contains()
?
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.
Nice catch, the assert was broken before then
database/postgres/postgres_test.go
Outdated
t.Fatal("Unexpected error, want permission denied error. Got: ", err) | ||
} | ||
|
||
if strings.Contains(e.Err, "permission denied for schema barfoo") { |
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.
Ditto with !strings.Contains()
…REATE query (golang-migrate#526) * Squash commits * Format * Minor refactoring * Address PR feedback; Add mustRun * Fix a test assert
This PR adds a check in
ensureVersionTable()
in order to prevent a CREATE query which may fail for read only users. As a result, read only users will be able to query the schema version.Closes #266