From ceedf8267904f4b68059897cf5a2bc11ed223a9e Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Thu, 18 Jun 2026 12:50:03 +0200 Subject: [PATCH] Map `inet` columns to `IpAddr` through `sqlx.toml` Every `inet` column holds a single host address, so a type override in the new per-crate `sqlx.toml` replaces the `as "col: IpAddr"` casts the queries needed to avoid the default `IpNetwork` mapping. Both crates using the query macros also pin `chrono` as the date/time crate. This needs the `sqlx-toml` feature on `sqlx`. `sqlx-cli` needs it too, as it refuses to run in a crate directory that contains a `sqlx.toml` file otherwise. It is a default feature of `sqlx-cli`, so only the `--no-default-features` install in the docs has to name it. --- Cargo.lock | 38 ++++++++++++++++++- Cargo.toml | 1 + ...d9148846724279e95cb9ff72468ede7ca5f3.json} | 6 +-- ...a51a989f02686ca3f9ea1182c01512b062c1.json} | 6 +-- ...279de2bf12d2b35c568769b97cc7559d428a.json} | 6 +-- ...5b02811cafaacb84e8e18dd5b6d1d0f5c3d1.json} | 6 +-- ...5751c53bccd0df633cadb51cde7612f20978.json} | 6 +-- ...639c51800e986b0fd08d9c9759792478bc0b.json} | 6 +-- ...3416938bb20fe0f406c601223d756b7f8f32.json} | 6 +-- ...3b6b5b68e0fe2a087e98a64e1d062a76f2a3.json} | 6 +-- ...1a66d7489b1f9e71647f8ef30cdeab7c24b8.json} | 6 +-- crates/storage-pg/sqlx.toml | 16 ++++++++ crates/storage-pg/src/compat/session.rs | 2 +- .../src/oauth2/device_code_grant.rs | 6 +-- crates/storage-pg/src/oauth2/session.rs | 2 +- crates/storage-pg/src/personal/session.rs | 2 +- crates/storage-pg/src/user/recovery.rs | 2 +- crates/storage-pg/src/user/registration.rs | 2 +- crates/storage-pg/src/user/session.rs | 2 +- crates/syn2mas/sqlx.toml | 12 ++++++ deny.toml | 3 ++ docs/development/database.md | 9 ++++- 22 files changed, 111 insertions(+), 40 deletions(-) rename crates/storage-pg/.sqlx/{query-e0dd18421e3b19079f291ba0ae9ba64031c0e635e5b40684a26565d50b3905f2.json => query-2fe8320d8d92e6361f83800a6387d9148846724279e95cb9ff72468ede7ca5f3.json} (91%) rename crates/storage-pg/.sqlx/{query-6b8d28b76d7ab33178b46dbb28c11e41d86f22b3fa899a952cad00129e59bee6.json => query-30538b3c249c37c64f37b66bea73a51a989f02686ca3f9ea1182c01512b062c1.json} (91%) rename crates/storage-pg/.sqlx/{query-9b7363000017fa3dee46441bc0679cb16f9f8df08fa258cc907007fb9bcd0bc7.json => query-3d240e280f1f207fc652ab3d1977279de2bf12d2b35c568769b97cc7559d428a.json} (92%) rename crates/storage-pg/.sqlx/{query-89674770c8d7929382e266a88937df017289d5cabe62ad00b115a2a408f4936b.json => query-65892801c9f79e25a82af2ce689e5b02811cafaacb84e8e18dd5b6d1d0f5c3d1.json} (92%) rename crates/storage-pg/.sqlx/{query-b91cc2458e1a530e7cadbd1ca3e2eaf93e1c44108b6770a24c9a24ac29db37d3.json => query-8f2533e9dd57add790826039820f5751c53bccd0df633cadb51cde7612f20978.json} (83%) rename crates/storage-pg/.sqlx/{query-f46e87bbb149b35e1d13b2b3cd2bdeab3c28a56a395f52f001a7bb013a5dfece.json => query-b07561f6f443417590054f1a5986639c51800e986b0fd08d9c9759792478bc0b.json} (83%) rename crates/storage-pg/.sqlx/{query-572ead41d62cfbe40e6f0c8edf6928e8eebd99036255b62d688ac02b5bd74b40.json => query-da85dd2a5b82b1ad9806047acee53416938bb20fe0f406c601223d756b7f8f32.json} (83%) rename crates/storage-pg/.sqlx/{query-ca8db2854f873a17f0ead6adfefe658aa71cade3ee70d17ee09a334599edc561.json => query-e3e60d6ab74ac0fbca59fa7d72043b6b5b68e0fe2a087e98a64e1d062a76f2a3.json} (92%) rename crates/storage-pg/.sqlx/{query-fd32368fa6cd16a9704cdea54f7729681d450669563dd1178c492ffce51e5ff2.json => query-e594f82c425e472737c9a0819eab1a66d7489b1f9e71647f8ef30cdeab7c24b8.json} (92%) create mode 100644 crates/storage-pg/sqlx.toml create mode 100644 crates/syn2mas/sqlx.toml diff --git a/Cargo.lock b/Cargo.lock index 3026ba47c..ae65f92d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5464,7 +5464,7 @@ dependencies = [ "ruma-identifiers-validation", "serde", "syn 2.0.106", - "toml", + "toml 1.1.2+spec-1.1.0", ] [[package]] @@ -5995,6 +5995,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + [[package]] name = "serde_spanned" version = "1.1.1" @@ -6302,6 +6311,7 @@ dependencies = [ "thiserror 2.0.18", "tokio", "tokio-stream", + "toml 0.8.23", "tracing", "url", "uuid", @@ -6841,6 +6851,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", + "toml_edit", +] + [[package]] name = "toml" version = "1.1.2+spec-1.1.0" @@ -6848,7 +6870,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee" dependencies = [ "serde_core", - "serde_spanned", + "serde_spanned 1.1.1", "toml_datetime 1.1.1+spec-1.1.0", "toml_parser", "winnow 1.0.3", @@ -6859,6 +6881,9 @@ name = "toml_datetime" version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] [[package]] name = "toml_datetime" @@ -6876,7 +6901,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap 2.14.0", + "serde", + "serde_spanned 0.6.9", "toml_datetime 0.6.11", + "toml_write", "winnow 0.7.13", ] @@ -6889,6 +6917,12 @@ dependencies = [ "winnow 1.0.3", ] +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + [[package]] name = "tonic" version = "0.14.2" diff --git a/Cargo.toml b/Cargo.toml index 1b9edb39e..2f46f532f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -635,6 +635,7 @@ features = [ "json", "uuid", "ipnetwork", + "sqlx-toml", ] # Custom error types diff --git a/crates/storage-pg/.sqlx/query-e0dd18421e3b19079f291ba0ae9ba64031c0e635e5b40684a26565d50b3905f2.json b/crates/storage-pg/.sqlx/query-2fe8320d8d92e6361f83800a6387d9148846724279e95cb9ff72468ede7ca5f3.json similarity index 91% rename from crates/storage-pg/.sqlx/query-e0dd18421e3b19079f291ba0ae9ba64031c0e635e5b40684a26565d50b3905f2.json rename to crates/storage-pg/.sqlx/query-2fe8320d8d92e6361f83800a6387d9148846724279e95cb9ff72468ede7ca5f3.json index 0c128fb28..9e462fd89 100644 --- a/crates/storage-pg/.sqlx/query-e0dd18421e3b19079f291ba0ae9ba64031c0e635e5b40684a26565d50b3905f2.json +++ b/crates/storage-pg/.sqlx/query-2fe8320d8d92e6361f83800a6387d9148846724279e95cb9ff72468ede7ca5f3.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT oauth2_device_code_grant_id\n , oauth2_client_id\n , scope\n , device_code\n , user_code\n , created_at\n , expires_at\n , fulfilled_at\n , rejected_at\n , exchanged_at\n , user_session_id\n , oauth2_session_id\n , ip_address as \"ip_address: IpAddr\"\n , user_agent\n , locale\n FROM\n oauth2_device_code_grant\n\n WHERE oauth2_device_code_grant_id = $1\n ", + "query": "\n SELECT oauth2_device_code_grant_id\n , oauth2_client_id\n , scope\n , device_code\n , user_code\n , created_at\n , expires_at\n , fulfilled_at\n , rejected_at\n , exchanged_at\n , user_session_id\n , oauth2_session_id\n , ip_address\n , user_agent\n , locale\n FROM\n oauth2_device_code_grant\n\n WHERE oauth2_device_code_grant_id = $1\n ", "describe": { "columns": [ { @@ -137,7 +137,7 @@ }, { "ordinal": 12, - "name": "ip_address: IpAddr", + "name": "ip_address", "type_info": "Inet", "origin": { "Table": { @@ -192,5 +192,5 @@ true ] }, - "hash": "e0dd18421e3b19079f291ba0ae9ba64031c0e635e5b40684a26565d50b3905f2" + "hash": "2fe8320d8d92e6361f83800a6387d9148846724279e95cb9ff72468ede7ca5f3" } diff --git a/crates/storage-pg/.sqlx/query-6b8d28b76d7ab33178b46dbb28c11e41d86f22b3fa899a952cad00129e59bee6.json b/crates/storage-pg/.sqlx/query-30538b3c249c37c64f37b66bea73a51a989f02686ca3f9ea1182c01512b062c1.json similarity index 91% rename from crates/storage-pg/.sqlx/query-6b8d28b76d7ab33178b46dbb28c11e41d86f22b3fa899a952cad00129e59bee6.json rename to crates/storage-pg/.sqlx/query-30538b3c249c37c64f37b66bea73a51a989f02686ca3f9ea1182c01512b062c1.json index 755d94962..0fdf5bfc3 100644 --- a/crates/storage-pg/.sqlx/query-6b8d28b76d7ab33178b46dbb28c11e41d86f22b3fa899a952cad00129e59bee6.json +++ b/crates/storage-pg/.sqlx/query-30538b3c249c37c64f37b66bea73a51a989f02686ca3f9ea1182c01512b062c1.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT oauth2_session_id\n , user_id\n , user_session_id\n , oauth2_client_id\n , scope_list\n , created_at\n , finished_at\n , user_agent\n , last_active_at\n , last_active_ip as \"last_active_ip: IpAddr\"\n , human_name\n FROM oauth2_sessions\n\n WHERE oauth2_session_id = $1\n ", + "query": "\n SELECT oauth2_session_id\n , user_id\n , user_session_id\n , oauth2_client_id\n , scope_list\n , created_at\n , finished_at\n , user_agent\n , last_active_at\n , last_active_ip\n , human_name\n FROM oauth2_sessions\n\n WHERE oauth2_session_id = $1\n ", "describe": { "columns": [ { @@ -104,7 +104,7 @@ }, { "ordinal": 9, - "name": "last_active_ip: IpAddr", + "name": "last_active_ip", "type_info": "Inet", "origin": { "Table": { @@ -144,5 +144,5 @@ true ] }, - "hash": "6b8d28b76d7ab33178b46dbb28c11e41d86f22b3fa899a952cad00129e59bee6" + "hash": "30538b3c249c37c64f37b66bea73a51a989f02686ca3f9ea1182c01512b062c1" } diff --git a/crates/storage-pg/.sqlx/query-9b7363000017fa3dee46441bc0679cb16f9f8df08fa258cc907007fb9bcd0bc7.json b/crates/storage-pg/.sqlx/query-3d240e280f1f207fc652ab3d1977279de2bf12d2b35c568769b97cc7559d428a.json similarity index 92% rename from crates/storage-pg/.sqlx/query-9b7363000017fa3dee46441bc0679cb16f9f8df08fa258cc907007fb9bcd0bc7.json rename to crates/storage-pg/.sqlx/query-3d240e280f1f207fc652ab3d1977279de2bf12d2b35c568769b97cc7559d428a.json index bc6cd6108..6c39731bf 100644 --- a/crates/storage-pg/.sqlx/query-9b7363000017fa3dee46441bc0679cb16f9f8df08fa258cc907007fb9bcd0bc7.json +++ b/crates/storage-pg/.sqlx/query-3d240e280f1f207fc652ab3d1977279de2bf12d2b35c568769b97cc7559d428a.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT compat_session_id\n , device_id\n , human_name\n , user_id\n , user_session_id\n , created_at\n , finished_at\n , is_synapse_admin\n , user_agent\n , last_active_at\n , last_active_ip as \"last_active_ip: IpAddr\"\n FROM compat_sessions\n WHERE compat_session_id = $1\n ", + "query": "\n SELECT compat_session_id\n , device_id\n , human_name\n , user_id\n , user_session_id\n , created_at\n , finished_at\n , is_synapse_admin\n , user_agent\n , last_active_at\n , last_active_ip\n FROM compat_sessions\n WHERE compat_session_id = $1\n ", "describe": { "columns": [ { @@ -115,7 +115,7 @@ }, { "ordinal": 10, - "name": "last_active_ip: IpAddr", + "name": "last_active_ip", "type_info": "Inet", "origin": { "Table": { @@ -144,5 +144,5 @@ true ] }, - "hash": "9b7363000017fa3dee46441bc0679cb16f9f8df08fa258cc907007fb9bcd0bc7" + "hash": "3d240e280f1f207fc652ab3d1977279de2bf12d2b35c568769b97cc7559d428a" } diff --git a/crates/storage-pg/.sqlx/query-89674770c8d7929382e266a88937df017289d5cabe62ad00b115a2a408f4936b.json b/crates/storage-pg/.sqlx/query-65892801c9f79e25a82af2ce689e5b02811cafaacb84e8e18dd5b6d1d0f5c3d1.json similarity index 92% rename from crates/storage-pg/.sqlx/query-89674770c8d7929382e266a88937df017289d5cabe62ad00b115a2a408f4936b.json rename to crates/storage-pg/.sqlx/query-65892801c9f79e25a82af2ce689e5b02811cafaacb84e8e18dd5b6d1d0f5c3d1.json index 176df6aac..0b0e74205 100644 --- a/crates/storage-pg/.sqlx/query-89674770c8d7929382e266a88937df017289d5cabe62ad00b115a2a408f4936b.json +++ b/crates/storage-pg/.sqlx/query-65892801c9f79e25a82af2ce689e5b02811cafaacb84e8e18dd5b6d1d0f5c3d1.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT oauth2_device_code_grant_id\n , oauth2_client_id\n , scope\n , device_code\n , user_code\n , created_at\n , expires_at\n , fulfilled_at\n , rejected_at\n , exchanged_at\n , user_session_id\n , oauth2_session_id\n , ip_address as \"ip_address: IpAddr\"\n , user_agent\n , locale\n FROM\n oauth2_device_code_grant\n\n WHERE user_code = $1\n ", + "query": "\n SELECT oauth2_device_code_grant_id\n , oauth2_client_id\n , scope\n , device_code\n , user_code\n , created_at\n , expires_at\n , fulfilled_at\n , rejected_at\n , exchanged_at\n , user_session_id\n , oauth2_session_id\n , ip_address\n , user_agent\n , locale\n FROM\n oauth2_device_code_grant\n\n WHERE device_code = $1\n ", "describe": { "columns": [ { @@ -137,7 +137,7 @@ }, { "ordinal": 12, - "name": "ip_address: IpAddr", + "name": "ip_address", "type_info": "Inet", "origin": { "Table": { @@ -192,5 +192,5 @@ true ] }, - "hash": "89674770c8d7929382e266a88937df017289d5cabe62ad00b115a2a408f4936b" + "hash": "65892801c9f79e25a82af2ce689e5b02811cafaacb84e8e18dd5b6d1d0f5c3d1" } diff --git a/crates/storage-pg/.sqlx/query-b91cc2458e1a530e7cadbd1ca3e2eaf93e1c44108b6770a24c9a24ac29db37d3.json b/crates/storage-pg/.sqlx/query-8f2533e9dd57add790826039820f5751c53bccd0df633cadb51cde7612f20978.json similarity index 83% rename from crates/storage-pg/.sqlx/query-b91cc2458e1a530e7cadbd1ca3e2eaf93e1c44108b6770a24c9a24ac29db37d3.json rename to crates/storage-pg/.sqlx/query-8f2533e9dd57add790826039820f5751c53bccd0df633cadb51cde7612f20978.json index 0184f5a96..8e67056ae 100644 --- a/crates/storage-pg/.sqlx/query-b91cc2458e1a530e7cadbd1ca3e2eaf93e1c44108b6770a24c9a24ac29db37d3.json +++ b/crates/storage-pg/.sqlx/query-8f2533e9dd57add790826039820f5751c53bccd0df633cadb51cde7612f20978.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT user_registration_id\n , ip_address as \"ip_address: IpAddr\"\n , user_agent\n , post_auth_action\n , username\n , display_name\n , terms_url\n , email_authentication_id\n , user_registration_token_id\n , hashed_password\n , hashed_password_version\n , upstream_oauth_authorization_session_id\n , created_at\n , completed_at\n FROM user_registrations\n WHERE user_registration_id = $1\n ", + "query": "\n SELECT user_registration_id\n , ip_address\n , user_agent\n , post_auth_action\n , username\n , display_name\n , terms_url\n , email_authentication_id\n , user_registration_token_id\n , hashed_password\n , hashed_password_version\n , upstream_oauth_authorization_session_id\n , created_at\n , completed_at\n FROM user_registrations\n WHERE user_registration_id = $1\n ", "describe": { "columns": [ { @@ -16,7 +16,7 @@ }, { "ordinal": 1, - "name": "ip_address: IpAddr", + "name": "ip_address", "type_info": "Inet", "origin": { "Table": { @@ -180,5 +180,5 @@ true ] }, - "hash": "b91cc2458e1a530e7cadbd1ca3e2eaf93e1c44108b6770a24c9a24ac29db37d3" + "hash": "8f2533e9dd57add790826039820f5751c53bccd0df633cadb51cde7612f20978" } diff --git a/crates/storage-pg/.sqlx/query-f46e87bbb149b35e1d13b2b3cd2bdeab3c28a56a395f52f001a7bb013a5dfece.json b/crates/storage-pg/.sqlx/query-b07561f6f443417590054f1a5986639c51800e986b0fd08d9c9759792478bc0b.json similarity index 83% rename from crates/storage-pg/.sqlx/query-f46e87bbb149b35e1d13b2b3cd2bdeab3c28a56a395f52f001a7bb013a5dfece.json rename to crates/storage-pg/.sqlx/query-b07561f6f443417590054f1a5986639c51800e986b0fd08d9c9759792478bc0b.json index 20f454736..731e445f6 100644 --- a/crates/storage-pg/.sqlx/query-f46e87bbb149b35e1d13b2b3cd2bdeab3c28a56a395f52f001a7bb013a5dfece.json +++ b/crates/storage-pg/.sqlx/query-b07561f6f443417590054f1a5986639c51800e986b0fd08d9c9759792478bc0b.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT\n user_recovery_session_id\n , email\n , user_agent\n , ip_address as \"ip_address: IpAddr\"\n , locale\n , created_at\n , consumed_at\n FROM user_recovery_sessions\n WHERE user_recovery_session_id = $1\n ", + "query": "\n SELECT\n user_recovery_session_id\n , email\n , user_agent\n , ip_address\n , locale\n , created_at\n , consumed_at\n FROM user_recovery_sessions\n WHERE user_recovery_session_id = $1\n ", "describe": { "columns": [ { @@ -38,7 +38,7 @@ }, { "ordinal": 3, - "name": "ip_address: IpAddr", + "name": "ip_address", "type_info": "Inet", "origin": { "Table": { @@ -96,5 +96,5 @@ true ] }, - "hash": "f46e87bbb149b35e1d13b2b3cd2bdeab3c28a56a395f52f001a7bb013a5dfece" + "hash": "b07561f6f443417590054f1a5986639c51800e986b0fd08d9c9759792478bc0b" } diff --git a/crates/storage-pg/.sqlx/query-572ead41d62cfbe40e6f0c8edf6928e8eebd99036255b62d688ac02b5bd74b40.json b/crates/storage-pg/.sqlx/query-da85dd2a5b82b1ad9806047acee53416938bb20fe0f406c601223d756b7f8f32.json similarity index 83% rename from crates/storage-pg/.sqlx/query-572ead41d62cfbe40e6f0c8edf6928e8eebd99036255b62d688ac02b5bd74b40.json rename to crates/storage-pg/.sqlx/query-da85dd2a5b82b1ad9806047acee53416938bb20fe0f406c601223d756b7f8f32.json index 7349527f7..7781fccae 100644 --- a/crates/storage-pg/.sqlx/query-572ead41d62cfbe40e6f0c8edf6928e8eebd99036255b62d688ac02b5bd74b40.json +++ b/crates/storage-pg/.sqlx/query-da85dd2a5b82b1ad9806047acee53416938bb20fe0f406c601223d756b7f8f32.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT s.user_session_id\n , s.created_at AS \"user_session_created_at\"\n , s.finished_at AS \"user_session_finished_at\"\n , s.user_agent AS \"user_session_user_agent\"\n , s.last_active_at AS \"user_session_last_active_at\"\n , s.last_active_ip AS \"user_session_last_active_ip: IpAddr\"\n , u.user_id\n , u.username AS \"user_username\"\n , u.created_at AS \"user_created_at\"\n , u.locked_at AS \"user_locked_at\"\n , u.deactivated_at AS \"user_deactivated_at\"\n , u.can_request_admin AS \"user_can_request_admin\"\n , u.is_guest AS \"user_is_guest\"\n FROM user_sessions s\n INNER JOIN users u\n USING (user_id)\n WHERE s.user_session_id = $1\n ", + "query": "\n SELECT s.user_session_id\n , s.created_at AS \"user_session_created_at\"\n , s.finished_at AS \"user_session_finished_at\"\n , s.user_agent AS \"user_session_user_agent\"\n , s.last_active_at AS \"user_session_last_active_at\"\n , s.last_active_ip AS \"user_session_last_active_ip\"\n , u.user_id\n , u.username AS \"user_username\"\n , u.created_at AS \"user_created_at\"\n , u.locked_at AS \"user_locked_at\"\n , u.deactivated_at AS \"user_deactivated_at\"\n , u.can_request_admin AS \"user_can_request_admin\"\n , u.is_guest AS \"user_is_guest\"\n FROM user_sessions s\n INNER JOIN users u\n USING (user_id)\n WHERE s.user_session_id = $1\n ", "describe": { "columns": [ { @@ -60,7 +60,7 @@ }, { "ordinal": 5, - "name": "user_session_last_active_ip: IpAddr", + "name": "user_session_last_active_ip", "type_info": "Inet", "origin": { "Table": { @@ -168,5 +168,5 @@ false ] }, - "hash": "572ead41d62cfbe40e6f0c8edf6928e8eebd99036255b62d688ac02b5bd74b40" + "hash": "da85dd2a5b82b1ad9806047acee53416938bb20fe0f406c601223d756b7f8f32" } diff --git a/crates/storage-pg/.sqlx/query-ca8db2854f873a17f0ead6adfefe658aa71cade3ee70d17ee09a334599edc561.json b/crates/storage-pg/.sqlx/query-e3e60d6ab74ac0fbca59fa7d72043b6b5b68e0fe2a087e98a64e1d062a76f2a3.json similarity index 92% rename from crates/storage-pg/.sqlx/query-ca8db2854f873a17f0ead6adfefe658aa71cade3ee70d17ee09a334599edc561.json rename to crates/storage-pg/.sqlx/query-e3e60d6ab74ac0fbca59fa7d72043b6b5b68e0fe2a087e98a64e1d062a76f2a3.json index 411045e7e..960f515fb 100644 --- a/crates/storage-pg/.sqlx/query-ca8db2854f873a17f0ead6adfefe658aa71cade3ee70d17ee09a334599edc561.json +++ b/crates/storage-pg/.sqlx/query-e3e60d6ab74ac0fbca59fa7d72043b6b5b68e0fe2a087e98a64e1d062a76f2a3.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT oauth2_device_code_grant_id\n , oauth2_client_id\n , scope\n , device_code\n , user_code\n , created_at\n , expires_at\n , fulfilled_at\n , rejected_at\n , exchanged_at\n , user_session_id\n , oauth2_session_id\n , ip_address as \"ip_address: IpAddr\"\n , user_agent\n , locale\n FROM\n oauth2_device_code_grant\n\n WHERE device_code = $1\n ", + "query": "\n SELECT oauth2_device_code_grant_id\n , oauth2_client_id\n , scope\n , device_code\n , user_code\n , created_at\n , expires_at\n , fulfilled_at\n , rejected_at\n , exchanged_at\n , user_session_id\n , oauth2_session_id\n , ip_address\n , user_agent\n , locale\n FROM\n oauth2_device_code_grant\n\n WHERE user_code = $1\n ", "describe": { "columns": [ { @@ -137,7 +137,7 @@ }, { "ordinal": 12, - "name": "ip_address: IpAddr", + "name": "ip_address", "type_info": "Inet", "origin": { "Table": { @@ -192,5 +192,5 @@ true ] }, - "hash": "ca8db2854f873a17f0ead6adfefe658aa71cade3ee70d17ee09a334599edc561" + "hash": "e3e60d6ab74ac0fbca59fa7d72043b6b5b68e0fe2a087e98a64e1d062a76f2a3" } diff --git a/crates/storage-pg/.sqlx/query-fd32368fa6cd16a9704cdea54f7729681d450669563dd1178c492ffce51e5ff2.json b/crates/storage-pg/.sqlx/query-e594f82c425e472737c9a0819eab1a66d7489b1f9e71647f8ef30cdeab7c24b8.json similarity index 92% rename from crates/storage-pg/.sqlx/query-fd32368fa6cd16a9704cdea54f7729681d450669563dd1178c492ffce51e5ff2.json rename to crates/storage-pg/.sqlx/query-e594f82c425e472737c9a0819eab1a66d7489b1f9e71647f8ef30cdeab7c24b8.json index 55d534349..663b7e953 100644 --- a/crates/storage-pg/.sqlx/query-fd32368fa6cd16a9704cdea54f7729681d450669563dd1178c492ffce51e5ff2.json +++ b/crates/storage-pg/.sqlx/query-e594f82c425e472737c9a0819eab1a66d7489b1f9e71647f8ef30cdeab7c24b8.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT personal_session_id\n , owner_user_id\n , owner_oauth2_client_id\n , actor_user_id\n , scope_list\n , created_at\n , revoked_at\n , human_name\n , last_active_at\n , last_active_ip as \"last_active_ip: IpAddr\"\n FROM personal_sessions\n\n WHERE personal_session_id = $1\n ", + "query": "\n SELECT personal_session_id\n , owner_user_id\n , owner_oauth2_client_id\n , actor_user_id\n , scope_list\n , created_at\n , revoked_at\n , human_name\n , last_active_at\n , last_active_ip\n FROM personal_sessions\n\n WHERE personal_session_id = $1\n ", "describe": { "columns": [ { @@ -104,7 +104,7 @@ }, { "ordinal": 9, - "name": "last_active_ip: IpAddr", + "name": "last_active_ip", "type_info": "Inet", "origin": { "Table": { @@ -132,5 +132,5 @@ true ] }, - "hash": "fd32368fa6cd16a9704cdea54f7729681d450669563dd1178c492ffce51e5ff2" + "hash": "e594f82c425e472737c9a0819eab1a66d7489b1f9e71647f8ef30cdeab7c24b8" } diff --git a/crates/storage-pg/sqlx.toml b/crates/storage-pg/sqlx.toml new file mode 100644 index 000000000..a4657ffc9 --- /dev/null +++ b/crates/storage-pg/sqlx.toml @@ -0,0 +1,16 @@ +# Copyright 2026 Element Creations Ltd. +# +# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial +# Please see LICENSE files in the repository root for full details. + +# Read by the `sqlx` query macros and by `sqlx-cli`, both of which need the +# `sqlx-toml` feature. + +[macros.preferred-crates] +# Keeps the macros on `chrono` if another date/time crate enters the dependency +# graph. +date-time = "chrono" + +[macros.type-overrides] +# `inet` columns only ever hold a single host address, never a network range. +'INET' = "std::net::IpAddr" diff --git a/crates/storage-pg/src/compat/session.rs b/crates/storage-pg/src/compat/session.rs index 087153af2..21dbd205f 100644 --- a/crates/storage-pg/src/compat/session.rs +++ b/crates/storage-pg/src/compat/session.rs @@ -308,7 +308,7 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> { , is_synapse_admin , user_agent , last_active_at - , last_active_ip as "last_active_ip: IpAddr" + , last_active_ip FROM compat_sessions WHERE compat_session_id = $1 "#, diff --git a/crates/storage-pg/src/oauth2/device_code_grant.rs b/crates/storage-pg/src/oauth2/device_code_grant.rs index 664082e50..f091e7e82 100644 --- a/crates/storage-pg/src/oauth2/device_code_grant.rs +++ b/crates/storage-pg/src/oauth2/device_code_grant.rs @@ -239,7 +239,7 @@ impl OAuth2DeviceCodeGrantRepository for PgOAuth2DeviceCodeGrantRepository<'_> { , exchanged_at , user_session_id , oauth2_session_id - , ip_address as "ip_address: IpAddr" + , ip_address , user_agent , locale FROM @@ -286,7 +286,7 @@ impl OAuth2DeviceCodeGrantRepository for PgOAuth2DeviceCodeGrantRepository<'_> { , exchanged_at , user_session_id , oauth2_session_id - , ip_address as "ip_address: IpAddr" + , ip_address , user_agent , locale FROM @@ -333,7 +333,7 @@ impl OAuth2DeviceCodeGrantRepository for PgOAuth2DeviceCodeGrantRepository<'_> { , exchanged_at , user_session_id , oauth2_session_id - , ip_address as "ip_address: IpAddr" + , ip_address , user_agent , locale FROM diff --git a/crates/storage-pg/src/oauth2/session.rs b/crates/storage-pg/src/oauth2/session.rs index 77fcc5287..dac85c40c 100644 --- a/crates/storage-pg/src/oauth2/session.rs +++ b/crates/storage-pg/src/oauth2/session.rs @@ -242,7 +242,7 @@ impl OAuth2SessionRepository for PgOAuth2SessionRepository<'_> { , finished_at , user_agent , last_active_at - , last_active_ip as "last_active_ip: IpAddr" + , last_active_ip , human_name FROM oauth2_sessions diff --git a/crates/storage-pg/src/personal/session.rs b/crates/storage-pg/src/personal/session.rs index 444edc6cc..ca71f2db7 100644 --- a/crates/storage-pg/src/personal/session.rs +++ b/crates/storage-pg/src/personal/session.rs @@ -215,7 +215,7 @@ impl PersonalSessionRepository for PgPersonalSessionRepository<'_> { , revoked_at , human_name , last_active_at - , last_active_ip as "last_active_ip: IpAddr" + , last_active_ip FROM personal_sessions WHERE personal_session_id = $1 diff --git a/crates/storage-pg/src/user/recovery.rs b/crates/storage-pg/src/user/recovery.rs index cfc1504eb..8e85fb6c2 100644 --- a/crates/storage-pg/src/user/recovery.rs +++ b/crates/storage-pg/src/user/recovery.rs @@ -101,7 +101,7 @@ impl UserRecoveryRepository for PgUserRecoveryRepository<'_> { user_recovery_session_id , email , user_agent - , ip_address as "ip_address: IpAddr" + , ip_address , locale , created_at , consumed_at diff --git a/crates/storage-pg/src/user/registration.rs b/crates/storage-pg/src/user/registration.rs index 1ee93d0b7..e05eb0391 100644 --- a/crates/storage-pg/src/user/registration.rs +++ b/crates/storage-pg/src/user/registration.rs @@ -129,7 +129,7 @@ impl UserRegistrationRepository for PgUserRegistrationRepository<'_> { UserRegistrationLookup, r#" SELECT user_registration_id - , ip_address as "ip_address: IpAddr" + , ip_address , user_agent , post_auth_action , username diff --git a/crates/storage-pg/src/user/session.rs b/crates/storage-pg/src/user/session.rs index ca48b0c05..2480f2107 100644 --- a/crates/storage-pg/src/user/session.rs +++ b/crates/storage-pg/src/user/session.rs @@ -204,7 +204,7 @@ impl BrowserSessionRepository for PgBrowserSessionRepository<'_> { , s.finished_at AS "user_session_finished_at" , s.user_agent AS "user_session_user_agent" , s.last_active_at AS "user_session_last_active_at" - , s.last_active_ip AS "user_session_last_active_ip: IpAddr" + , s.last_active_ip AS "user_session_last_active_ip" , u.user_id , u.username AS "user_username" , u.created_at AS "user_created_at" diff --git a/crates/syn2mas/sqlx.toml b/crates/syn2mas/sqlx.toml new file mode 100644 index 000000000..fbbccdea6 --- /dev/null +++ b/crates/syn2mas/sqlx.toml @@ -0,0 +1,12 @@ +# Copyright 2026 Element Creations Ltd. +# +# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial +# Please see LICENSE files in the repository root for full details. + +# Read by the `sqlx` query macros and by `sqlx-cli`, both of which need the +# `sqlx-toml` feature. + +[macros.preferred-crates] +# Keeps the macros on `chrono` if another date/time crate enters the dependency +# graph. +date-time = "chrono" diff --git a/deny.toml b/deny.toml index 6535477bd..0ea557c35 100644 --- a/deny.toml +++ b/deny.toml @@ -82,6 +82,9 @@ skip = [ { name = "serde_html_form", version = "0.2.8" }, # axum-extra { name = "toml_datetime", version = "0.6.11" }, # proc-macro-crate -> toml_edit { name = "winnow", version = "0.7.13" }, # cron, toml_edit + # sqlx-core's `sqlx-toml` feature is still on toml 0.8 + { name = "toml", version = "0.8.23" }, + { name = "serde_spanned", version = "0.6.9" }, # hyper-util -> system-configuration depends on this old version { name = "core-foundation", version = "0.9.4" }, # wasmtime pulls in older versions of these diff --git a/docs/development/database.md b/docs/development/database.md index 2deafce2b..3c0e2dac9 100644 --- a/docs/development/database.md +++ b/docs/development/database.md @@ -30,14 +30,19 @@ Usually it does so by having the database available at compile time, but to avoi Preparing this flat file is done through `sqlx-cli`, and should be done everytime the database schema or the queries changed. ```sh -# Install the CLI -cargo install sqlx-cli --no-default-features --features postgres +# Install the CLI. The `sqlx-toml` feature is required because the CLI refuses +# to run in a crate directory that contains a `sqlx.toml` file without it. +cargo install sqlx-cli --no-default-features --features postgres,sqlx-toml cd crates/storage-pg/ # Must be in the mas-storage-pg crate folder export DATABASE_URL=postgresql:///matrix_auth cargo sqlx prepare ``` +Both `mas-storage-pg` and `syn2mas` use the query macros and have their own +`.sqlx` cache and `sqlx.toml`. The `misc/sqlx_update.sh` script regenerates both +in one go (it also sets up the temporary tables `syn2mas` needs). + ## Migrations Migration files live in the `migrations` folder in the `mas-storage-pg` crate.