-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: Move lock out of ensureVersionTable, for consistency with other SQL operations #173
Conversation
28d6012
to
0e286b8
Compare
1 similar comment
Pull Request Test Coverage Report for Build 344
💛 - 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 your investigation.
I think a cleaner approach would be to not create the schema version table in Drop()
and instead rely on WithInstance()
to create it. I don't think many users would need an empty schema version table after a successful DROP
.
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.
Add a test case for this to prevent a regression.
@dhui looking at the MySQL implementation as reference, it simply doesn't lock the database when calling I think the behaviour should be similar in the two, should I simply remove the locking logic around Edit: otherwise, if we want to remove |
This work would be greatly appreciated! MySQL isn't the only driver that uses
So for consistency, we should lock in |
Alright, I will update the PR tomorrow. |
0e286b8
to
dc76765
Compare
I'd leave the name as is since it's sufficiently descriptive. After all, adding every bit of functionality to the function's name would result in really long function names. |
@dhui I added a test-case, but only for Postgresql, as I don't know enough about most of the other databases. Also, please be aware of this change: The change in behaviour in Drop (namely that it leaves an empty database), breaks some logic in these test-cases (and possibly in user-code as well). Finally, it's worth mentioning that the order of ensureLock / ensureVersion has been swapped in CockroachDB, in order to facilitate locking in ensureVersion |
Btw, it looks like coverage is only measured for MongoDB and not all databases: |
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 making the changes to all of the DB drivers for consistency and for the review guidance!
The change in behaviour in Drop (namely that it leaves an empty database), breaks some logic in these test-cases (and possibly in user-code as well).
I'll note this in the release notes. People should not have been relying on this undocumented behavior so I don't consider this a breaking change.
Btw, it looks like coverage is only measured for MongoDB and not all databases:
https://coveralls.io/builds/21705329
I'm not sure why this is happening... This issue is being tracked here: #2
database/postgres/postgres_test.go
Outdated
} | ||
|
||
// drop the table | ||
if err := d.Drop(); 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.
This test should be using migrate's Drop()
implementation instead of the driver's to test that the lock isn't being twice.
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.
Hmm... The migrate is a parent-package which the database package doesn't know, so it wouldn't make sense to use migrate's Drop()
here. Then the test should be moved to the migrate_test.go
or another test file in the root package but that doesn't test the specific database implementations.
I guess we would need a suite that does integration-tests on migrate and all the different database implementation which would be a rather significant addition.
I could add such a suite, but it would only cover the Drop()
method, as I don't have the time to write migrations for each database.
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.
Yeah, I wanna avoid scope creep, but also want to prevent a regression. We don't need to test the other methods. e.g. only testing Drop()
is sufficient. The test in it's current form doesn't cover any different cases than the existing TestDrop()
in database/testing/testing.go
.
The quickest way (albeit less clean way) to add the proper regression test would be to import github.com/golang-migrate/migrate/v4
in database/testing/testing.go
, create a migrate.Migrate
instance using NewWithDatabaseInstance()
in Test()
, and test Drop()
using that instance.
I'm all for adding a db driver <-> migrate integration test suite, but I'm not sure about the approach you have for this. The scope for such an integration test suite may also be quite large, so for now, let's add the regression test using the quick and dirty way mentioned above. Then we can add a db driver integration test suite and clean the code in a separate PR.
Thanks again for your work!
…Table from Drop across all database implementations
afef6f1
to
f111488
Compare
I went a bit rogue and made some changes. I found that a change to the Driver interface was warranted. With the change to the functionality in Logic for choosing the default MigrationsTable, was moved to this For the regression test, found here: I wanted to keep it completely separate from the existing tests, so I had to duplicate some code in order to call the I just duplicated the whole test-block when Example: @dhui what do you think of these changes? Does the change to the Driver interface make sense to you? |
…rop() between database implementations and migrate
f111488
to
3fd5314
Compare
That's fine since it's already done. In the future, I'd prefer that we squash commits after PR approval but before merging to cleanup the history to make reviewing easier. However your comments summarizing your changes have been quite useful!
I'd avoid making any changes to the |
Alright, reverted the changes and instead added a warning to the |
…ialized database connections
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.
Since you've already gone through the trouble of creating a separate integration test, can you also use a separate entrypoint from the each driver test? e.g. call dt.TestMigrate()
from a new TestMigrate()
test method instead of Test()
in each driver test.
The following db drivers need an integration test (e.g. call dt.TestMigrate()
):
- Cassandra
- Clickhouse
I'm surprised that the integration tests don't add to the total test runtime... I guess it's b/c they're running in parallel w/ the existing tests.
Sorry for abusing your test-server btw and testing-by-pushing, but I can't run Docker locally. I don't have enough RAM in this PC. |
Alright, in order to create a I aligned the folder structure in the database implementations, such that they all have the migration examples in |
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.
Sorry for the delayed review. I've been quite busy lately.
Thanks for making the example file structure consistent.
I like how all of the examples are executed now!
The TravisCI runs take longer now, but we can deal w/ this issue later. Maybe sprinkle t.Parallel()
around...
It looks like there was an issue backing out your Initialize()
changes. Namely, setting default config values was removed. I've marked the places that need to be fixed.
Thanks for the PR! |
Fixes #164 .
ensureVersionTable
seems to be the only SQL operation in the postgres driver which handles locking of database itself, meaning it seems to break the convention of having the caller responsible for locking and not the callee.This removes the locking logic from
ensureVersionTable
and makes sure to properly lock the database before callingensureVersionTable
from theWithInstance
method.