Skip to content

Commit e44b5e8

Browse files
committed
Add Snowflake support in database handling and enhance logging
- Introduced Snowflake as a supported database in the enum and related logic. - Updated SQL table creation to include Snowflake-specific syntax. - Enhanced logging for file modification checks in both local and database contexts.
1 parent b8b90a5 commit e44b5e8

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/filesystem.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ impl FileSystem {
4545
) -> anyhow::Result<bool> {
4646
let local_path = self.safe_local_path(app_state, path, priviledged)?;
4747
let local_result = file_modified_since_local(&local_path, since).await;
48+
log::trace!(
49+
"Local file {} modified since {since:?} ? {local_result:?}",
50+
local_path.display()
51+
);
4852
match (local_result, &self.db_fs_queries) {
4953
(Ok(modified), _) => Ok(modified),
5054
(Err(e), Some(db_fs)) if e.kind() == ErrorKind::NotFound => {
@@ -212,6 +216,7 @@ impl DbFsQueries {
212216
match dbms {
213217
SupportedDatabase::Mssql => "CREATE TABLE sqlpage_files(path NVARCHAR(255) NOT NULL PRIMARY KEY, contents VARBINARY(MAX), last_modified DATETIME2(3) NOT NULL DEFAULT CURRENT_TIMESTAMP);",
214218
SupportedDatabase::Postgres => "CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents BYTEA, last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
219+
SupportedDatabase::Snowflake => "CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents VARBINARY, last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
215220
_ => "CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents BLOB, last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
216221
}
217222
}
@@ -278,16 +283,20 @@ impl DbFsQueries {
278283
self.was_modified.sql(),
279284
(since, path)
280285
);
281-
query
286+
let was_modified_i32 = query
282287
.fetch_optional(&app_state.db.connection)
283288
.await
284-
.map(|modified| modified == Some((1,)))
285289
.with_context(|| {
286290
format!(
287291
"Unable to check when {} was last modified in the database",
288292
path.display()
289293
)
290-
})
294+
})?;
295+
log::trace!(
296+
"DB File {} was modified result: {was_modified_i32:?}",
297+
path.display()
298+
);
299+
Ok(was_modified_i32 == Some((1,)))
291300
}
292301

293302
async fn read_file(&self, app_state: &AppState, path: &Path) -> anyhow::Result<Vec<u8>> {
@@ -345,6 +354,7 @@ async fn test_sql_file_read_utf8() -> anyhow::Result<()> {
345354
let db = &state.db;
346355
let conn = &db.connection;
347356
conn.execute("DROP TABLE IF EXISTS sqlpage_files").await?;
357+
log::debug!("Creating table sqlpage_files: {create_table_sql}");
348358
conn.execute(create_table_sql).await?;
349359

350360
let dbms = db.info.kind;

src/webserver/database/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub enum SupportedDatabase {
2222
Postgres,
2323
MySql,
2424
Mssql,
25+
Snowflake,
2526
Generic,
2627
}
2728

@@ -34,6 +35,7 @@ impl SupportedDatabase {
3435
"postgres" | "postgresql" => Self::Postgres,
3536
"mysql" | "mariadb" => Self::MySql,
3637
"mssql" | "sql server" | "microsoft sql server" => Self::Mssql,
38+
"snowflake" => Self::Snowflake,
3739
_ => Self::Generic,
3840
}
3941
}
@@ -46,6 +48,7 @@ impl SupportedDatabase {
4648
Self::Postgres => "PostgreSQL",
4749
Self::MySql => "MySQL",
4850
Self::Mssql => "Microsoft SQL Server",
51+
Self::Snowflake => "Snowflake",
4952
Self::Generic => "Generic",
5053
}
5154
}

src/webserver/database/sql.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use sqlparser::ast::{
1515
SelectFlavor, SelectItem, Set, SetExpr, Spanned, Statement, Value, ValueWithSpan, Visit,
1616
VisitMut, Visitor, VisitorMut,
1717
};
18-
use sqlparser::dialect::{Dialect, MsSqlDialect, MySqlDialect, PostgreSqlDialect, SQLiteDialect};
18+
use sqlparser::dialect::{
19+
Dialect, MsSqlDialect, MySqlDialect, PostgreSqlDialect, SQLiteDialect, SnowflakeDialect,
20+
};
1921
use sqlparser::parser::{Parser, ParserError};
2022
use sqlparser::tokenizer::Token::{self, SemiColon, EOF};
2123
use sqlparser::tokenizer::{TokenWithSpan, Tokenizer};
@@ -248,6 +250,7 @@ fn dialect_for_db(dbms: SupportedDatabase) -> Box<dyn Dialect> {
248250
SupportedDatabase::Mssql => Box::new(MsSqlDialect {}),
249251
SupportedDatabase::MySql => Box::new(MySqlDialect {}),
250252
SupportedDatabase::Sqlite => Box::new(SQLiteDialect {}),
253+
SupportedDatabase::Snowflake => Box::new(SnowflakeDialect {}),
251254
}
252255
}
253256

@@ -1137,15 +1140,15 @@ mod test {
11371140
];
11381141

11391142
fn create_test_db_info(database_type: SupportedDatabase) -> DbInfo {
1140-
let (dbms_name, kind) = match database_type {
1141-
SupportedDatabase::Postgres => ("PostgreSQL".to_string(), AnyKind::Postgres),
1142-
SupportedDatabase::Mssql => ("Microsoft SQL Server".to_string(), AnyKind::Mssql),
1143-
SupportedDatabase::MySql => ("MySQL".to_string(), AnyKind::MySql),
1144-
SupportedDatabase::Sqlite => ("SQLite".to_string(), AnyKind::Sqlite),
1145-
SupportedDatabase::Generic => ("Generic".to_string(), AnyKind::Postgres), // fallback
1143+
let kind = match database_type {
1144+
SupportedDatabase::Postgres => AnyKind::Postgres,
1145+
SupportedDatabase::Mssql => AnyKind::Mssql,
1146+
SupportedDatabase::MySql => AnyKind::MySql,
1147+
SupportedDatabase::Sqlite => AnyKind::Sqlite,
1148+
_ => AnyKind::Odbc,
11461149
};
11471150
DbInfo {
1148-
dbms_name,
1151+
dbms_name: database_type.display_name().to_string(),
11491152
database_type,
11501153
kind,
11511154
}

0 commit comments

Comments
 (0)