MCPcopy Create free account
hub / github.com/erans/pgsqlite / get_current_version

Method get_current_version

src/migration/runner.rs:299–334  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

297 }
298
299 fn get_current_version(&self) -> Result<u32> {
300 // First check if metadata table exists
301 let metadata_exists = self.conn.query_row(
302 "SELECT 1 FROM sqlite_master WHERE type='table' AND name='__pgsqlite_metadata'",
303 [],
304 |_| Ok(true)
305 ).unwrap_or(false);
306
307 if !metadata_exists {
308 // Check if we have the original __pgsqlite_schema table
309 let has_pgsqlite_schema = self.conn.query_row(
310 "SELECT 1 FROM sqlite_master WHERE type='table' AND name='__pgsqlite_schema'",
311 [],
312 |_| Ok(true)
313 ).unwrap_or(false);
314
315 if has_pgsqlite_schema {
316 // This is a pre-migration database, but we need to verify
317 // it hasn't been marked as version 1 yet
318 return Ok(0);
319 } else {
320 // Brand new database
321 return Ok(0);
322 }
323 }
324
325 // Metadata table exists, get version from it
326 match self.conn.query_row(
327 "SELECT value FROM __pgsqlite_metadata WHERE key = 'schema_version'",
328 [],
329 |row| row.get::<_, String>(0)
330 ) {
331 Ok(version) => Ok(version.parse::<u32>()?),
332 Err(_) => Ok(0), // Metadata exists but no version set
333 }
334 }
335
336 fn has_legacy_schema(&self) -> Result<bool> {
337 // Check if we have the original __pgsqlite_schema table

Callers 2

check_schema_versionMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected