Skip to content

chore: add extensions to schema cache #468

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

Merged
merged 2 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions crates/pgt_schema_cache/src/extensions.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 2 additions & 0 deletions crates/pgt_schema_cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![allow(dead_code)]

mod columns;
mod extensions;
mod functions;
mod policies;
mod roles;
Expand All @@ -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::*;
Expand Down
10 changes: 10 additions & 0 deletions crates/pgt_schema_cache/src/queries/extensions.sql
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions crates/pgt_schema_cache/src/schema_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down