+
+ LEGEND |
+
+
+ Type |
+ Example |
+
+
+
+ Primary Key
|
+ {{ data_type("integer", "nextval", none, "NO") }} |
+
+
+
+
+ Standard Field
|
+ {{ data_type("bytea", none, none, "NO") }} |
+
+
+
+ Nullable Field
|
+ {{ data_type("text", none, none, "YES") }} |
+
+
+
+ Sized Field
|
+ {{ data_type("varchar", none, 32, "NO") }} |
+
+
+
+ Autoincrement Field
|
+ {{ data_type("integer", "nextval", none, "NO") }} |
+
+
+
+ >];
+
+ {% for relation in schema.relations %}
+ "{{relation.on_table}}":"{{relation.on_field}}_out" -> "{{relation.to_table}}":"{{relation.to_field}}"
+ {% endfor %}
+
+
+}
diff --git a/utilities/dbviz/src/lib.rs b/utilities/dbviz/src/lib.rs
new file mode 100644
index 000000000..2a0f48add
--- /dev/null
+++ b/utilities/dbviz/src/lib.rs
@@ -0,0 +1,2 @@
+//! Intentionally empty
+//! This file exists, so that doc tests can be used inside binary crates.
diff --git a/utilities/dbviz/src/main.rs b/utilities/dbviz/src/main.rs
new file mode 100644
index 000000000..a22d08ac4
--- /dev/null
+++ b/utilities/dbviz/src/main.rs
@@ -0,0 +1,39 @@
+//! `DBViz` - Database Diagram Generator
+//!
+//! `DBViz` is a tool for generating database diagrams.
+
+mod opts;
+mod postgresql;
+mod schema;
+
+use std::fs;
+
+use anyhow::Result;
+use minijinja::{context, Environment};
+
+fn main() -> Result<()> {
+ let opts = opts::load();
+
+ let loader = postgresql::Conn::new(&opts)?;
+ let schema = loader.load()?;
+
+ let template_file = match &opts.template {
+ Some(fname) => fs::read_to_string(fname)?,
+ None => include_str!("default_template.jinja").to_string(),
+ };
+
+ let mut env = Environment::new();
+ env.add_template("diagram", &template_file)?;
+ let tmpl = env.get_template("diagram")?;
+
+ let ctx = context!(
+ opts => opts,
+ schema => schema
+ );
+
+ let rendered = tmpl.render(ctx)?;
+
+ println!("{rendered}");
+
+ Ok(())
+}
diff --git a/utilities/dbviz/src/opts.rs b/utilities/dbviz/src/opts.rs
new file mode 100644
index 000000000..43d38d13d
--- /dev/null
+++ b/utilities/dbviz/src/opts.rs
@@ -0,0 +1,74 @@
+//! CLI Option parsing
+
+use std::path::PathBuf;
+
+use clap::{Args, Parser};
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Parser, Clone, Serialize, Deserialize)]
+#[command(author, version, about, long_about = None)]
+/// `DBViz` a tool for generating database diagrams.
+pub(crate) struct Cli {
+ #[command(flatten)]
+ /// Postgres connection options
+ pub(crate) pg_opts: Pg,
+
+ #[arg(short, long)]
+ /// Tables to include in the current diagram.
+ pub(crate) include_tables: Option