Skip to content

Commit b651c75

Browse files
authored
chore: add extensions to schema cache (#468)
1 parent e745328 commit b651c75

File tree

5 files changed

+78
-8
lines changed

5 files changed

+78
-8
lines changed

.sqlx/query-3ebf3d74eb9d0448d675882c7f8a23f1440c250590de976c5c46c5edf6746faf.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use sqlx::PgPool;
2+
3+
use crate::schema_cache::SchemaCacheItem;
4+
5+
#[derive(Debug, Default)]
6+
pub struct Extension {
7+
pub name: String,
8+
pub schema: Option<String>,
9+
pub default_version: String,
10+
pub installed_version: Option<String>,
11+
pub comment: Option<String>,
12+
}
13+
14+
impl SchemaCacheItem for Extension {
15+
type Item = Extension;
16+
17+
async fn load(pool: &PgPool) -> Result<Vec<Extension>, sqlx::Error> {
18+
sqlx::query_file_as!(Extension, "src/queries/extensions.sql")
19+
.fetch_all(pool)
20+
.await
21+
}
22+
}

crates/pgt_schema_cache/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![allow(dead_code)]
44

55
mod columns;
6+
mod extensions;
67
mod functions;
78
mod policies;
89
mod roles;
@@ -14,6 +15,7 @@ mod types;
1415
mod versions;
1516

1617
pub use columns::*;
18+
pub use extensions::Extension;
1719
pub use functions::{Behavior, Function, FunctionArg, FunctionArgs, ProcKind};
1820
pub use policies::{Policy, PolicyCommand};
1921
pub use roles::*;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SELECT
2+
e.name as "name!",
3+
n.nspname AS schema,
4+
e.default_version as "default_version!",
5+
x.extversion AS installed_version,
6+
e.comment
7+
FROM
8+
pg_available_extensions() e(name, default_version, comment)
9+
LEFT JOIN pg_extension x ON e.name = x.extname
10+
LEFT JOIN pg_namespace n ON x.extnamespace = n.oid

crates/pgt_schema_cache/src/schema_cache.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ impl SchemaCache {
4949
})
5050
}
5151

52-
/// Applies an AST node to the repository
53-
///
54-
/// For example, alter table add column will add the column to the table if it does not exist
55-
/// yet
56-
pub fn mutate(&mut self) {
57-
unimplemented!();
58-
}
59-
6052
pub fn find_table(&self, name: &str, schema: Option<&str>) -> Option<&Table> {
6153
self.tables
6254
.iter()

0 commit comments

Comments
 (0)