migrant_lib icon indicating copy to clipboard operation
migrant_lib copied to clipboard

Support passing a connection to use

Open jaemk opened this issue 5 years ago • 1 comments

Instead of creating a new connection for each operation, which is cruft related to #25 . This would also unblock #6

jaemk avatar Jan 31 '20 07:01 jaemk

This would be great! I happen to have an issue now with migrant when using Postgres. I want to setup our tests to use separate schemas, but since every time migrant is making a new connection and I can't SET SESSION SCHEMA test_X.

I good starting point would be to:

  • ~Use Lazy to establish connection only once and use it for all migrations: https://crates.io/crates/once_cell~ This won't work
  • Storing a connection inside the Config (maybe a more accurate name could be used) and wrapping it in Arc for cheap cloning
  • Ideally using tokio_postgres (https://crates.io/crates/tokio-postgres/). This connection could even be passed when you have connection pools like https://crates.io/crates/bb8 (sync), https://crates.io/crates/r2d2 (sync), https://crates.io/crates/deadpool (async), etc
  • it would be nice to have both sync and async apis

These are my thoughts, I thought I would share them with you. What do you think?

elpiel avatar Apr 12 '21 10:04 elpiel