-
Notifications
You must be signed in to change notification settings - Fork 231
feat: add configurable write_functions #1236
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
base: main
Are you sure you want to change the base?
Changes from all commits
5007cfc
6db6130
d2113ab
9a26426
a7fefc4
27e7766
6d6f69d
773067f
a41b9e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -565,6 +565,18 @@ pub struct QueryParser { | |
| pub engine: QueryParserEngine, | ||
| } | ||
|
|
||
| /// Per-database write function classification. | ||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, Default, JsonSchema)] | ||
| #[serde(rename_all = "snake_case", deny_unknown_fields)] | ||
| pub struct WriteFunctions { | ||
| /// Database name. | ||
| pub database: String, | ||
| /// Functions that should be treated as write-only. | ||
| /// Each entry can be schema-qualified. | ||
| #[serde(default)] | ||
| pub functions: Vec<String>, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You want something like this: [[write_functions]]
database = "prod"
name = "create_partition"
schema = "partman"This allows you to disambiguiate between the same function created in different schemas. It's not a common edge case, but it can happen, and we want to be able to scope all Postgres primitives we scan for using a fully qualified identifier. I know that functions can be overloaded, so we should consider capturing parameter data types as well, but for read/write separation it seems unlikely that one version of the function reads and the other one writes, so maybe that's not necessary for this. |
||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::Config; | ||
|
|
@@ -588,4 +600,18 @@ database = "production" | |
| QueryParserEngine::PgQueryProtobuf | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn write_functions_reads_default_values_from_config() { | ||
| let source = r#" | ||
| [[write_functions]] | ||
| database = "production" | ||
| "#; | ||
|
|
||
| let config: Config = toml::from_str(source).unwrap(); | ||
|
|
||
| assert_eq!(config.write_functions.len(), 1); | ||
| assert_eq!(config.write_functions[0].database, "production"); | ||
| assert!(config.write_functions[0].functions.is_empty()); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.