summaryrefslogtreecommitdiff
path: root/src/migrations.rs
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-11 15:48:45 -0600
committermo khan <mo@mokhan.ca>2025-06-11 15:48:45 -0600
commitdbd3c780f27bd5bee23adf6e280b84d669230e0d (patch)
tree21969009f17f8d58e35cf9a73a3ed77eb0e3faca /src/migrations.rs
parentaea6bd6ec7d7e70a67723edf6327df4a9cc65d89 (diff)
test: fix commented out tests
Diffstat (limited to 'src/migrations.rs')
-rw-r--r--src/migrations.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/migrations.rs b/src/migrations.rs
index 5076a9e..61c5b19 100644
--- a/src/migrations.rs
+++ b/src/migrations.rs
@@ -62,12 +62,28 @@ impl<'a> MigrationRunner<'a> {
}
fn get_current_version(&self) -> Result<i32> {
- let version = self.conn.query_row(
- "SELECT COALESCE(MAX(version), 0) FROM schema_migrations",
+ // Check if schema_migrations table exists first
+ let table_exists = self.conn.query_row(
+ "SELECT name FROM sqlite_master WHERE type='table' AND name='schema_migrations'",
[],
- |row| row.get::<_, i32>(0),
- )?;
- Ok(version)
+ |_| Ok(()),
+ );
+
+ match table_exists {
+ Ok(_) => {
+ // Table exists, get the current version
+ let version = self.conn.query_row(
+ "SELECT COALESCE(MAX(version), 0) FROM schema_migrations",
+ [],
+ |row| row.get::<_, i32>(0),
+ )?;
+ Ok(version)
+ }
+ Err(_) => {
+ // Table doesn't exist, we're at version 0
+ Ok(0)
+ }
+ }
}
fn run_migration(&self, migration: &Migration) -> Result<()> {