From f66ad9cce8f9b05be82f5ce90511b9c4d5167cc2 Mon Sep 17 00:00:00 2001
From: psteinroe <philipp@steinroetter.com>
Date: Wed, 23 Jul 2025 08:54:03 +0200
Subject: [PATCH 1/2] chore: add extensions to schema cache

---
 crates/pgt_schema_cache/src/extensions.rs     | 22 +++++++++++++++++++
 crates/pgt_schema_cache/src/lib.rs            |  2 ++
 .../src/queries/extensions.sql                | 10 +++++++++
 crates/pgt_schema_cache/src/schema_cache.rs   |  8 -------
 4 files changed, 34 insertions(+), 8 deletions(-)
 create mode 100644 crates/pgt_schema_cache/src/extensions.rs
 create mode 100644 crates/pgt_schema_cache/src/queries/extensions.sql

diff --git a/crates/pgt_schema_cache/src/extensions.rs b/crates/pgt_schema_cache/src/extensions.rs
new file mode 100644
index 00000000..8494397c
--- /dev/null
+++ b/crates/pgt_schema_cache/src/extensions.rs
@@ -0,0 +1,22 @@
+use sqlx::PgPool;
+
+use crate::schema_cache::SchemaCacheItem;
+
+#[derive(Debug, Default)]
+pub struct Extension {
+    pub name: String,
+    pub schema: Option<String>,
+    pub default_version: String,
+    pub installed_version: Option<String>,
+    pub comment: Option<String>,
+}
+
+impl SchemaCacheItem for Extension {
+    type Item = Extension;
+
+    async fn load(pool: &PgPool) -> Result<Vec<Extension>, sqlx::Error> {
+        sqlx::query_file_as!(Extension, "src/queries/extensions.sql")
+            .fetch_all(pool)
+            .await
+    }
+}
diff --git a/crates/pgt_schema_cache/src/lib.rs b/crates/pgt_schema_cache/src/lib.rs
index b67f9412..6440cd01 100644
--- a/crates/pgt_schema_cache/src/lib.rs
+++ b/crates/pgt_schema_cache/src/lib.rs
@@ -3,6 +3,7 @@
 #![allow(dead_code)]
 
 mod columns;
+mod extensions;
 mod functions;
 mod policies;
 mod roles;
@@ -14,6 +15,7 @@ mod types;
 mod versions;
 
 pub use columns::*;
+pub use extensions::Extension;
 pub use functions::{Behavior, Function, FunctionArg, FunctionArgs, ProcKind};
 pub use policies::{Policy, PolicyCommand};
 pub use roles::*;
diff --git a/crates/pgt_schema_cache/src/queries/extensions.sql b/crates/pgt_schema_cache/src/queries/extensions.sql
new file mode 100644
index 00000000..aedc71b2
--- /dev/null
+++ b/crates/pgt_schema_cache/src/queries/extensions.sql
@@ -0,0 +1,10 @@
+SELECT
+  e.name as "name!",
+  n.nspname AS schema,
+  e.default_version as "default_version!",
+  x.extversion AS installed_version,
+  e.comment
+FROM
+  pg_available_extensions() e(name, default_version, comment)
+  LEFT JOIN pg_extension x ON e.name = x.extname
+  LEFT JOIN pg_namespace n ON x.extnamespace = n.oid
diff --git a/crates/pgt_schema_cache/src/schema_cache.rs b/crates/pgt_schema_cache/src/schema_cache.rs
index 8fb9683b..df7239ea 100644
--- a/crates/pgt_schema_cache/src/schema_cache.rs
+++ b/crates/pgt_schema_cache/src/schema_cache.rs
@@ -49,14 +49,6 @@ impl SchemaCache {
         })
     }
 
-    /// Applies an AST node to the repository
-    ///
-    /// For example, alter table add column will add the column to the table if it does not exist
-    /// yet
-    pub fn mutate(&mut self) {
-        unimplemented!();
-    }
-
     pub fn find_table(&self, name: &str, schema: Option<&str>) -> Option<&Table> {
         self.tables
             .iter()

From 4ce449402f99d7e92a38412fbb453462d6abd67d Mon Sep 17 00:00:00 2001
From: psteinroe <philipp@steinroetter.com>
Date: Wed, 23 Jul 2025 09:23:07 +0200
Subject: [PATCH 2/2] chore: add sqlx preprare query

---
 ...a23f1440c250590de976c5c46c5edf6746faf.json | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 .sqlx/query-3ebf3d74eb9d0448d675882c7f8a23f1440c250590de976c5c46c5edf6746faf.json

diff --git a/.sqlx/query-3ebf3d74eb9d0448d675882c7f8a23f1440c250590de976c5c46c5edf6746faf.json b/.sqlx/query-3ebf3d74eb9d0448d675882c7f8a23f1440c250590de976c5c46c5edf6746faf.json
new file mode 100644
index 00000000..1b922062
--- /dev/null
+++ b/.sqlx/query-3ebf3d74eb9d0448d675882c7f8a23f1440c250590de976c5c46c5edf6746faf.json
@@ -0,0 +1,44 @@
+{
+  "db_name": "PostgreSQL",
+  "query": "SELECT\n  e.name as \"name!\",\n  n.nspname AS schema,\n  e.default_version as \"default_version!\",\n  x.extversion AS installed_version,\n  e.comment\nFROM\n  pg_available_extensions() e(name, default_version, comment)\n  LEFT JOIN pg_extension x ON e.name = x.extname\n  LEFT JOIN pg_namespace n ON x.extnamespace = n.oid\n",
+  "describe": {
+    "columns": [
+      {
+        "ordinal": 0,
+        "name": "name!",
+        "type_info": "Name"
+      },
+      {
+        "ordinal": 1,
+        "name": "schema",
+        "type_info": "Name"
+      },
+      {
+        "ordinal": 2,
+        "name": "default_version!",
+        "type_info": "Text"
+      },
+      {
+        "ordinal": 3,
+        "name": "installed_version",
+        "type_info": "Text"
+      },
+      {
+        "ordinal": 4,
+        "name": "comment",
+        "type_info": "Text"
+      }
+    ],
+    "parameters": {
+      "Left": []
+    },
+    "nullable": [
+      null,
+      true,
+      null,
+      true,
+      null
+    ]
+  },
+  "hash": "3ebf3d74eb9d0448d675882c7f8a23f1440c250590de976c5c46c5edf6746faf"
+}
