Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

Postgres DB connection not closed after migrations? #7

Closed
justinas opened this issue Aug 19, 2014 · 4 comments
Closed

Postgres DB connection not closed after migrations? #7

justinas opened this issue Aug 19, 2014 · 4 comments
Labels

Comments

@justinas
Copy link
Contributor

Migrate does not seem to close the database after running migrations.

Might not be issue for most usage, but in my case, it is, as I am trying to use temporary databases for testing that are destroyed afterwards. Right now, I can't do this, because dropping a database with open connections to it is... tricky.

I think this could be done with Driver having a Close (Cleanup, ...?) method that would be called after migrations by Up, Down, etc.

@mattes
Copy link
Owner

mattes commented Aug 24, 2014

Sorry for my late reply. I was on vacation last week.

Migrate does not seem to close the database after running migrations.

Ah, good point. I see two options:

  1. Remove Initialize(url string) error and move all logic from there to Migrate(file file.File, pipe chan interface{}). This means, for every migration file that get's applied, it would open (and close) a connection.
  2. Keep Initialize(url string) error and add Close() error which handles all DB connection closing, once all migration files are applied.

I like option 1 more but not sure about the opening/ closing overhead. What do you think?

@mattes mattes added the bug label Aug 25, 2014
mattes added a commit that referenced this issue Aug 25, 2014
@mattes
Copy link
Owner

mattes commented Aug 25, 2014

After some more thoughts, I think it makes more sense to implement option 2. I added a Close() error func to the driver.

@justinas can you check if it works for you, too?

@justinas
Copy link
Contributor Author

Sorry for delay on my part as well. Option 2 certainly looks more flexible. Just tested it and it seems to work for me.

@mattes
Copy link
Owner

mattes commented Aug 25, 2014

Great. Will close this issue then.

@mattes mattes closed this as completed Aug 25, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants