Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update diesel, diesel_migrations, and uuid
This implements the major upgrade of the Diesel crate from version 1 to version 2. The relevant changes are the following: - Diesel now requires mutable access to the `Connection` to perform any database interaction [0]. - The Diesel derive attributes need to be wrapped by `diesel()` now [1]. - The diesel_migration crate has been completely rewritten and the `embed_migrations!()` macro had to be replaced [2]. - The `connection::Connection::transaction` closure now takes one argument (the database connection). See [3] vs. [4]. - I also decided to rename `database_connection` to `conn` in these cases to better differentiate the two (we could keep/shadow the outer variable for a smaller diff but it seems cleaner that way). Note: The `Arc<PgConnection> -> Arc<Mutex<PgConnection>>` change is only intended as a PoC. It is not a good idea as the mutex locking makes some of the async blocks/code completely pointless. This problem already existed before though. The documentation sates that the requirement of mutable connections is expected to be a "straightforward change as the connection already can execute only one query at a time". So this change should only make matters worse by moving the locking up and therefore increasing the time for which locks are held. This should only make the execution a bit slower (not sure if it would even be noticeable) but it increases the risk of deadlocks which is the real danger. To avoid this issue we should use a connection pool instead (e.g., via r2d2) but there are alternatives like trying to move the locking further down in the code again or rewriting the database logic. [0]: https://diesel.rs/guides/migration_guide.html#2-0-0-mutable-connection [1]: https://diesel.rs/guides/migration_guide.html#2-0-0-derive-attributes [2]: https://diesel.rs/guides/migration_guide.html#2-0-0-upgrade-migrations [3]: https://docs.diesel.rs/2.0.x/diesel/connection/trait.Connection.html#method.transaction [4]: https://docs.diesel.rs/1.4.x/diesel/connection/trait.Connection.html#method.transaction
- Loading branch information