1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! A CLI for managing sql-audit. Running this binary expects to find a file called "audit.toml"
//! in the current directory. It will use the config in that file in order to:
//! 1. Create a new schema called `sql_audit`
//! 2. Create a table in that schema called `audit`
//! 3. Create a new function called `sql_audit_trigger`
//! 4. Create a trigger on all tables in the `public` schema not excluded which inserts a new record
//! into `sql_audit.audit` any time an insert, update, or delete occurs containing copies of
//! all the data.
//!
//! ## Locals
//! When performing transactions within that `public` schema, you can set some local values in a
//! transaction to track additional data.
//! 1. `SET LOCAL sql_audit.app_user = 'some_app_user';` is useful for recording an
//! application-level user you want to track changes against, separate from the database user.
//! 2. `SET LOCAL sql_audit.request_id = 'some request';` can be used for tracing multiple row
//! changes against a single operation (e.g. web request).
//!
//! ## audit.toml
//! Here are the configuration values you can provide in your `audit.toml`
//! ```toml
//! database = "postgres://user:password@host:port/database" # the database connection string
//! exclude_tables = ["some_table"] # A list of tables to exclude.
//! ```
use Result;
use Deserialize;
async